Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 4th, 2005, 02:02 PM
Registered User
 
Join Date: Jul 2005
Location: Banjaluka, , Bosnia and Herzegovina.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default c++ faster than Pascal

Hi there!
I'm going to informatic competition and i need to decide which programing language to use. I know Pascal better, but it look's like c++ is faster! Look at this progam:

//c++
#include <iostream.h>
#include <conio.h>
pauza();

main()
{
int x,y;
x=0; y=0;
while(y<=25)
{
x++; y++;
gotoxy(x,y);
cout <<"*";
pauza();
}
cout <<"Program zavrsen";
cin >>x;
return 0;
}
pauza()
{int i,j;
for (i=1; i<=30000; i++)
    for (j=1; j<=10000; j++);
return 0;
}

--------------------------------------------------------------
and the same program in pascal:

program crtez;
uses wincrt;
var x,y:integer;

procedure pauza;
var i,j:integer;
begin
for i:=1 to maxint do
    for j:=1 to 1000 do
end;

begin
x:=0; y:=0;
while y<25 do
      begin
      inc(x); inc(y);
      gotoxy (x,y);
      write ('*');
      pauza;
      end;
write ('Program zavrsen');
readln;
end.
-------------------------------------------------
The c++ program finished in 16.14 seconds (on Athlon 2200+), and the Pascal one in 29.41! And there is time limit on the competition.

What do you sugest?
Thanks!

Reply With Quote
  #2 (permalink)  
Old August 4th, 2005, 02:24 PM
Registered User
 
Join Date: Jul 2005
Location: Banjaluka, , Bosnia and Herzegovina.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And, a little corection in Pascal code:
+-------------------------+
| procedure pauza; |
| var i,j:integer; |
| begin |
| for i:=1 to 30000 do |
| for j:=1 to 1000 do |
| end; |
+-------------------------+
But, the time diference is still big. If it means something, I use borland c++ 5.0 and Pascal 1.5
:(

Reply With Quote
  #3 (permalink)  
Old August 5th, 2005, 02:13 AM
Authorized User
 
Join Date: Mar 2005
Location: Wagga Wagga, NSW, Australia.
Posts: 60
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Alan-LB Send a message via Yahoo to Alan-LB
Default

Unless you are just considering the competition environment, you cant make a direct comparison between the speeds of the programs like that.

If you talk about the two languages in general, it would very much depend on which compilers you were going to use in the future and how they optimize the raw code.

Borland C++ 5.0 has now been superceded and the newer compilers may well produce faster code.

It may be better to make your decision on which Language to use on how widely C++ is used in comparison with Pascal. (Borland Pascal is now obsolete having given way to Delphi).

C++ with classes, templates, standard template libraries and other advanced facilities is a much more versatile language than Pascal (IMHO). (I have used both Botland Pascal since version 5.5 in 1990 and C++ since about 1993).

Certainly C++ is used far more widely than Pascal and also gives rise to many derivative languages such as Java, C# and several more.

Is the time limit on the running speed of your program or on how long it takes you to write the program and get it going? If it is the latter, then choose the language that you know the best.

Good luck

Alan




Reply With Quote
  #4 (permalink)  
Old August 5th, 2005, 11:59 AM
Registered User
 
Join Date: Jul 2005
Location: Banjaluka, , Bosnia and Herzegovina.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

On this type of competition, we have about 3 or 4 hours (I don't know exactly) to code solutions of 4 problems. The comision then checks .exe files on the referent mashine. If program execute longer then some standard time (that is defined for every problem) you don't get points, even the solution is good. So important is the time limit on the running speed of my program.
As I alredy said, i know Pacal bether than c++, but it looks like algorithms in Pascal run slower.


Reply With Quote
  #5 (permalink)  
Old August 5th, 2005, 09:27 PM
Authorized User
 
Join Date: Jul 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I agree with you here in terms of coding time.

It takes much less time to code in C++ because there are many shortcut methods.

Hence in a competition, one using C++ has an edge over those using Pascle as C++ saves coding time. :)

However, be warned that C++ takes much more time to debug if you happen to make mistakes. In other words, unless you are an expert in C++, it is relatively difficult to debug.

------------------------------
Programming ( Assignment / Project ) Help

John Dirk
Programming Consulant
http://www.programminghelp4u.com - Programming (Assignment/Project) Help
Reply With Quote
  #6 (permalink)  
Old August 6th, 2005, 12:08 AM
Authorized User
 
Join Date: Mar 2005
Location: Wagga Wagga, NSW, Australia.
Posts: 60
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Alan-LB Send a message via Yahoo to Alan-LB
Default

I would use the language you are most familiar with so that you can code the quickest. Then spend time checking your code thoroughly and optimising it as much as possible. Also prepare, if you can, by finding out how the compiler you will be using will optimise your code so you can make the best of the compiler.

As in all situations like this don't be tempted to rush - take it slowly and carefully.

Good luck - let us know what your decision was and how you performed.

Alan



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Suggestion for better / faster processing elygp SQL Server 2000 2 February 13th, 2008 10:47 PM
which is faster pegasus51 Ajax 3 December 30th, 2007 08:56 AM
They Want It To Be Faster! kindler Access 7 December 20th, 2005 10:54 AM
Pascal Triangle mistry_bhavin C++ Programming 2 November 15th, 2005 01:43 AM
Any faster? Ben Access VBA 19 March 12th, 2004 07:04 PM



All times are GMT -4. The time now is 06:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.