 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

August 4th, 2005, 02:02 PM
|
Registered User
|
|
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|

August 4th, 2005, 02:24 PM
|
Registered User
|
|
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
:(
|

August 5th, 2005, 02:13 AM
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 58
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|

August 5th, 2005, 11:59 AM
|
Registered User
|
|
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

August 5th, 2005, 09:27 PM
|
Authorized User
|
|
Join Date: Jul 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

August 6th, 2005, 12:08 AM
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 58
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|
 |