Mail Archives: djgpp/1999/03/22/17:02:10
//I have noticed that C++ executables produced by the gxx
//compiler and run in plain DOS are somewhat faster (15%)
//than those produced by the g++ compiler and run in linux.
//Nate Eldredge has told me that he does not see why that
//should be so and has advised me to look at the times using
//the profiler gprof available in djgpp and linux. But in
//trying to follow his advice I found that djgpp is not
//running gprof correctly. The timings seem to be
//factor two (approximately) too low.
//Here is a short program (test.cc) which proves my assertion
//that djgpp is not running gprof correctly. Compile it in
//djgpp with
// gxx -pg test.cc -o test.exe
//and then run it
// C:\> test
//and then profile it
// C:\> gprof test.exe > file1
//(send output to file1 because the output usually too long to
//view on screen).
//
//Compile it in linux with
// # g++ -pg test.cc -o test.exe
//and run it
// # /directory/test.exe
//where directory is the directory into which you put test.cc.
//Profile it
// # gprof test.exe > file1
//You will see that the timings done in the test code using time.h
//say the total time required is about 32 seconds (200 mhz pentium
//pro) whether one is running djgpp or linux. You will see that
//the linux output of gprof confirms the 32 seconds and says that
//main and zadd take about the same amount of time (16 seconds).
//However, you will see that the djgpp output of gprof says that
//main and zadd both take about 8 seconds, and that the total time
//is about 16 seconds, all a factor two too low as I asserted.
//My questions are: Is this a known problem? Have I made some
//error?
#include <iostream.h>
#include <time.h> //use when timing (benchmarking)
extern int zadd(void);
unsigned int imax=400000000;
main()
{unsigned int i,j;
clock_t start_time, end_time; //declaration statement for times
start_time=clock(); //set start time
for (i=1;i<imax+1;i++) j=i+i;
zadd(); //this does same thing that the previous line does
//therefore runtime for main and time for this
//subroutine should be approximately equal
end_time=clock(); //set end time
cout<<"clock ticks"<<'\t'<<end_time - start_time<<'\n';
cout<<"ticks/second"<<'\t'<<CLOCKS_PER_SEC<<'\n';
cout<<"time"<<'\t'<<(end_time-start_time)/CLOCKS_PER_SEC<<'\n';
}
int zadd(void)
{unsigned int i,j;
for (i=1;i<imax+1;i++) j=i+i;
return 0;
}
- Raw text -