python - Why runtime in C is so random? -
I have this code in Python:
time import time from a = 0 C Xrange (10 ** 3) for x = time (): print x print time () - c
is the time of the Rune which I expected.
0.508999824524 0.263000011444 0.25200009346 0.25200009346
Since the program is cached on the kernel, the timing of the python is halfway? I think?
But it's getting random at C.
#include & lt; Stdio.h & gt; # Include & lt; Time.h> Int main () {int a = 0; Clock_t Tik = clock (); For (a = 0; a & lt; 1000; a ++) {printf ("% d", one); } Clock_t tac = clock (); Printf ("% f", (double) (tick-tick) / 1000000); }
The price given by the clock, one of the amount of CPU time consumed by The guess is the process. This is not the time when you make that call, but it receives certain variables from the scheduler.
Use clock_gettime (CLOCK_MONOTONIC, ...)
for an accurate figure.
Comments
Post a Comment