|
From: <mo...@ju...> - 2002-08-16 04:58:52
|
Running the program below in Dev-C++, Version 4, took between 209 and 235
seconds on my system. I don't know why the running times vary, but even
taking the fastest time of 209 seconds, it compares unfavorably with a
similar program compiled (36 seconds) or interpreted (55 seconds) in
QBasic 4 .
Does Dev-C++ really produce such leisurely code? Or can the program be
speeded up?
Allan
// This program prints (1) integers 1 to 1,000,000
// (2) starting & ending times
//======================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
struct tm *ptr;
time_t loc_time;
long int x;
loc_time = time(NULL);
ptr = localtime(&loc_time);
for (x = 1;x <= 1000000;x++)
printf("%d ",x);
printf("\nStarting time is ");
printf(asctime(ptr));
loc_time = time(NULL);
ptr = localtime(&loc_time);
printf("\nEnding time is ");
printf(asctime(ptr), "\n");
system ("PAUSE");
return 0;
}
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today! For your FREE software, visit:
http://dl.www.juno.com/get/web/.
|
|
From: Abhijit S. <mu...@gm...> - 2002-08-16 09:03:30
|
Greets. > Running the program below in Dev-C++, Version 4, took between 209 and 235 > seconds on my system. I don't know why the running times vary, but even > taking the fastest time of 209 seconds, it compares unfavorably with a > similar program compiled (36 seconds) or interpreted (55 seconds) in > QBasic 4 . > > Does Dev-C++ really produce such leisurely code? Or can the program be > speeded up? I think the problem is with your settings. On mine, MingW32(Dev) takes 130 seconds, and BC++ 5.5 takes 138 seconds. Check that debugging mode is not enabled in 'Compiler Options' > 'Linker' and 'Best Optimization' is selected under the 'Code Generation/Optimizations' page. To perform manual optimzations in multi-function programs, use the profiler to see where most of the activity is taking place, and speed up those parts. Oh, wait... I just tried that and it gave me an "access violation at address 0052b937, read of address 0x00..08". But I added it to a project and then tried, and it went fine. Dev has many problems handling files without a project. Can someone look into this, please? |
|
From: Per W. <pw...@ia...> - 2002-08-16 13:51:13
|
What should be noted is that your test code doesn't test the speed of the Dev-Cpp++-generated program - which in fact is the MingGW- or Cygwin-genrated - but instead measures the time to process a couple of million bytes of output to standard out. Do you redicrect the output, or is it scrolling in a text window. What size is the text window etc. This kind of programs also notoriosly generates a large percent of system (kernel) time, giving the OS scheduler some extra concerns about how to schedule between this and other programs. /PWM EMA System email: pw...@ia... Per Westermark web: http://iapetus.neab.net Vargvaegen 174B phone: +46 8 410 17 198 S-906 42 Umeaa Sweden On Fri, 16 Aug 2002 mo...@ju... wrote: > Running the program below in Dev-C++, Version 4, took between 209 and 235 > seconds on my system. I don't know why the running times vary, but even > taking the fastest time of 209 seconds, it compares unfavorably with a > similar program compiled (36 seconds) or interpreted (55 seconds) in > QBasic 4 . > > Does Dev-C++ really produce such leisurely code? Or can the program be > speeded up? > > Allan > > // This program prints (1) integers 1 to 1,000,000 > // (2) starting & ending times > //====================================================== > #include <stdio.h> > #include <stdlib.h> > #include <time.h> > > int main(int argc, char *argv[]) > { > struct tm *ptr; > time_t loc_time; > long int x; > > loc_time = time(NULL); > ptr = localtime(&loc_time); > > for (x = 1;x <= 1000000;x++) > printf("%d ",x); > > printf("\nStarting time is "); > printf(asctime(ptr)); > > loc_time = time(NULL); > ptr = localtime(&loc_time); > printf("\nEnding time is "); > printf(asctime(ptr), "\n"); > > system ("PAUSE"); > > return 0; > } > > ________________________________________________________________ > GET INTERNET ACCESS FROM JUNO! > Juno offers FREE or PREMIUM Internet access for less! > Join Juno today! For your FREE software, visit: > http://dl.www.juno.com/get/web/. > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ho...> - 2002-08-16 14:06:49
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of mo...@ju...
> Sent: Friday, August 16, 2002 8:02 AM
> To: dev...@li...
> Subject: [Dev-C++] speed test
>
>
> Running the program below in Dev-C++, Version 4, took between
> 209 and 235
> seconds on my system. I don't know why the running times
> vary, but even
> taking the fastest time of 209 seconds, it compares unfavorably with a
> similar program compiled (36 seconds) or interpreted (55 seconds) in
> QBasic 4 .
Did you printed the result after every x++ inside the for loop in QB?
>
> Does Dev-C++ really produce such leisurely code? Or can the
> program be
> speeded up?
Of course it can. Printing in console is slow (the time cost of a
function call, etc).
>
> Allan
>
> // This program prints (1) integers 1 to 1,000,000
> // (2) starting & ending times
> //======================================================
> #include <stdio.h>
> #include <stdlib.h>
> #include <time.h>
>
> int main(int argc, char *argv[])
Theese arguments are not needed.
> {
> struct tm *ptr;
> time_t loc_time;
> long int x;
>
> loc_time = time(NULL);
No accurate results with this method.
> ptr = localtime(&loc_time);
>
> for (x = 1;x <= 1000000;x++)
> printf("%d ",x);
Here you have 100000 function calls for printing in the console.
>
> printf("\nStarting time is ");
> printf(asctime(ptr));
>
> loc_time = time(NULL);
> ptr = localtime(&loc_time);
> printf("\nEnding time is ");
> printf(asctime(ptr), "\n");
>
> system ("PAUSE");
>
> return 0;
> }
A better program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
clock_t t1, t2;
long int x;
t1=clock();
for (x = 1; x <= 1000000;x++)
;
printf("%ld\n", x);
t2=clock();
printf("\n\nProcessor time: %lu", (unsigned long)t2-t1);
printf("\nIn seconds: %f\n\n", (double)(t2-t1)/CLOCKS_PER_SEC);
system ("PAUSE");
return 0;
}
The above prints the final value of x only.
Using MINGW GCC 3.1 with optimizations:
gcc temp.c -o temp -ansi -pedantic-errors -Wall
-fexpensive-optimizations -O3 -ffloat-store -mcpu=pentiumpro
C:\c>temp
1000001
Processor time: 0
In seconds: 0.000000
Press any key to continue . . .
Here obviously the compiler performed an optimisation with which he saw
the final result of the loop and avoided the loop completely.
Running the GCC 3.1 without the optimisation switches:
C:\c>gcc temp.c -o temp -ansi -pedantic-errors -Wall
C:\c>temp
1000001
Processor time: 10
In seconds: 0.010000
Press any key to continue . . .
Here it performed the loop and it took it 10 msec (something similar
will happen with Dev-C++ eith optimisations off).
In summary, your time cost was imposed due to 1000000 function calls to
printf().
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Ioannis V. <no...@ho...> - 2002-08-16 14:14:30
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Ioannis Vranos
> Sent: Friday, August 16, 2002 5:06 PM
> To: dev...@li...
> Subject: RE: [Dev-C++] speed test
>
>
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...] On Behalf
> > Of mo...@ju...
> > Sent: Friday, August 16, 2002 8:02 AM
> > To: dev...@li...
> > Subject: [Dev-C++] speed test
> >
> >
> > Running the program below in Dev-C++, Version 4, took between
> > 209 and 235
> > seconds on my system. I don't know why the running times
> > vary, but even
> > taking the fastest time of 209 seconds, it compares
> unfavorably with a
> > similar program compiled (36 seconds) or interpreted (55
> seconds) in
> > QBasic 4 .
>
>
> Did you printed the result after every x++ inside the for loop in QB?
>
>
>
> >
> > Does Dev-C++ really produce such leisurely code? Or can the
> > program be
> > speeded up?
>
>
> Of course it can. Printing in console is slow (the time cost of a
> function call, etc).
>
>
>
> >
> > Allan
> >
> > // This program prints (1) integers 1 to 1,000,000
> > // (2) starting & ending times
> > //======================================================
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <time.h>
> >
> > int main(int argc, char *argv[])
>
> Theese arguments are not needed.
>
>
> > {
> > struct tm *ptr;
> > time_t loc_time;
> > long int x;
> >
> > loc_time = time(NULL);
>
>
> No accurate results with this method.
>
>
>
> > ptr = localtime(&loc_time);
> >
> > for (x = 1;x <= 1000000;x++)
> > printf("%d ",x);
>
>
> Here you have 100000 function calls for printing in the console.
>
>
> >
> > printf("\nStarting time is ");
> > printf(asctime(ptr));
> >
> > loc_time = time(NULL);
> > ptr = localtime(&loc_time);
> > printf("\nEnding time is ");
> > printf(asctime(ptr), "\n");
> >
> > system ("PAUSE");
> >
> > return 0;
> > }
>
>
> A better program:
>
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <time.h>
>
> int main()
> {
> clock_t t1, t2;
>
> long int x;
>
> t1=clock();
>
> for (x = 1; x <= 1000000;x++)
> ;
>
> printf("%ld\n", x);
>
> t2=clock();
>
> printf("\n\nProcessor time: %lu", (unsigned long)t2-t1);
> printf("\nIn seconds: %f\n\n", (double)(t2-t1)/CLOCKS_PER_SEC);
>
> system ("PAUSE");
>
> return 0;
> }
>
>
>
> The above prints the final value of x only.
>
>
>
> Using MINGW GCC 3.1 with optimizations:
>
>
> gcc temp.c -o temp -ansi -pedantic-errors -Wall
> -fexpensive-optimizations -O3 -ffloat-store -mcpu=pentiumpro
>
>
> C:\c>temp
> 1000001
>
>
> Processor time: 0
> In seconds: 0.000000
>
> Press any key to continue . . .
>
>
>
> Here obviously the compiler performed an optimisation with
> which he saw
> the final result of the loop and avoided the loop completely.
>
>
> Running the GCC 3.1 without the optimisation switches:
>
>
> C:\c>gcc temp.c -o temp -ansi -pedantic-errors -Wall
>
> C:\c>temp
> 1000001
>
>
> Processor time: 10
> In seconds: 0.010000
>
> Press any key to continue . . .
>
>
>
> Here it performed the loop and it took it 10 msec (something similar
> will happen with Dev-C++ eith optimisations off).
>
>
> In summary, your time cost was imposed due to 1000000
> function calls to
> printf().
Also even if you use printf() inside the for loop, things will go much
faster if you minimize the console (command prompt) window during the
execution. And this because windows will not have to display every
number.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|