Watch Accuracy ()

I saw a lot of messages about using the clock () function to determine the amount of elapsed time in a program with code that looks something like this:

start_time = clock();

//code to be timed
.
.
.

end_time = clock();
elapsed_time = (end_time - start_time) / CLOCKS_PER_SEC;

The value of CLOCKS_PER_SEC is almost certainly not the actual number of measures per second, so I'm a little afraid of the result. Without worrying about streaming and I / O, is the output of the clock () function scalable in some way so that this divison gives the correct wall clock time?

+1
source share
1 answer

The answer to your question is yes.

clock() , CPU, . , , , , CLOCKS_PER_SEC 1000. , clock() , .

, . rdtsc "" - . (, Intel Core 2) . .

, clock(), , . "rdtsc" .

+2

Source: https://habr.com/ru/post/1691370/


All Articles