K
Kevin Klein
I am talking of C/C++ on unix platform using gcc. So feel free
to take off any crossposted NG's if others are not offended,
but I seek generic C/C++ and also unix and gcc specific answers.
Essentially:
/1/ How do I time a program in seconds or CPU cycles?
/2/ How do I use the facilities to increase performance of
any given program?
/3/ CPU has many clocks I have heard. There is also a bus
clock.
/4/ I looked in a number of books. I found a little on time.h.
But being humble, I thought I would ask experts as well.
I have played with the statements like:
#include <time.h>
cycles=10000;
start = clock();
for (i=0; i<cycles; i++){
return = slowfunction( arguments );
}
end = clock( );
printf("Start time: %d, Stop time: %d, CLOCKS_PER_SEC: %d\nSeconds for %d calls: %f \n",
start, end, CLOCKS_PER_SEC, cycles, ((dbl)(end - start)/CLOCKS_PER_SEC) );
printf("Ticks for %d calls: %f \n", cycles, difftime(end, start) );
// I am not exactly clear about CLOCKS_PER_SEC, difftime() .
// I wrote this w/o clear conceptual understanding .
// But I want clear concept so I know it works before I write it.
// Using: gcc 2.7.2.3
Kevin Klein
to take off any crossposted NG's if others are not offended,
but I seek generic C/C++ and also unix and gcc specific answers.
Essentially:
/1/ How do I time a program in seconds or CPU cycles?
/2/ How do I use the facilities to increase performance of
any given program?
/3/ CPU has many clocks I have heard. There is also a bus
clock.
/4/ I looked in a number of books. I found a little on time.h.
But being humble, I thought I would ask experts as well.
I have played with the statements like:
#include <time.h>
cycles=10000;
start = clock();
for (i=0; i<cycles; i++){
return = slowfunction( arguments );
}
end = clock( );
printf("Start time: %d, Stop time: %d, CLOCKS_PER_SEC: %d\nSeconds for %d calls: %f \n",
start, end, CLOCKS_PER_SEC, cycles, ((dbl)(end - start)/CLOCKS_PER_SEC) );
printf("Ticks for %d calls: %f \n", cycles, difftime(end, start) );
// I am not exactly clear about CLOCKS_PER_SEC, difftime() .
// I wrote this w/o clear conceptual understanding .
// But I want clear concept so I know it works before I write it.
// Using: gcc 2.7.2.3
Kevin Klein