c++ - The C `clock()` function just returns a zero -


itemprop = "text">

C clock () function just gives me a zero. I tried to use different types, with no improvement ... it is to measure the time with a good way good precision

  # & lt ;? Time.h & gt; # Include & lt; Stdio.h & gt; Int main () {clock_t start, end; Double cpu_time_used; Four [32]; Start = clock (); Printf ("\ nSleeping 3 seconds ... \ n \ n"); Sleep (3); End = clock (); Cpu_time_used = ((double) (end-of-end)) / ((double) CLOCKS_PER_SEC); Printf ("start =% .20f \ nend =% .20f \ n", start, end); Printf ("delta =% .20f \ n", ((double) (end-start)); Printf ( "Cpu_taim_used =% Kl5f \ n", Cpu_taim_used); Printf ("CLOCKS_PER_SEC =% I \ n \ n", CLOCKS_PER_SEC); Return 0; }  
  3 seconds Sleeping ... start = 0k00000000000000000000 end = .00000000000000000000 delta = 0.00000000000000000000 cpu_time_used = 0.000000000000000 CLOCKS_PER_SEC = 1000000  

platform: Intel 32-bit, RedHat Linux, gcc 3.4.6

< code> clock () CPU report using the sleep () does not use any CPU time, your results may be perfect, just what do you want .


Comments