How to calculate a C / C ++ program running time

To calculate a couple of days ago with a running time of algorithm implemented in C ++, on the use of clock()this function. Procedure substantially as follows:

clock_t start,end;
start = clock();
/*my code*/
end = clock();
result = end-start;

Because the clock()return is about milliseconds, and I expect the running time in advance also millisecond level, so it seek death is directly end-startcalculated, but did not use (double)(end-start)/CLOCKS_PER_SECto seconds for the calculations.

Because time is no way to write a Linux system, it is first written in the Windows system, then ported to run on Linux. Found 1,000 times as much as the output difference, attitude directly collapse. Disheartened, surf the Internet and other timing methods, stumbled on the article under Linux clock timing learning function , suddenly. Here the record about, then step to avoid the pit.

Guess you like

Origin www.cnblogs.com/multhree/p/12084137.html