当前位置:网站首页>C language to get program running time

C language to get program running time

2022-07-05 17:01:00 Oh-liuxing

#include <stdio.h>
#include <time.h>
int main(){ 
  printf("hello word\n");
  printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);
  return 0;
}

explain :(1) Timing function clock() Returns the time the program has run so far , In Milliseconds . Call it before the program ends , You can get the running time of the whole program . This time is divided by a constant CLOCKS_PER_SEC The resulting value is expressed in “ second ” In units of .
(2) stay VC++6.0 in time.h Constants defined by the next macro CLOCKS_PER_SEC, Its value is 1000.
#define CLOCKS_PER_SEC 1000
about CLOCKS_PER_SEC, It's used to show how many clock units there are in a second , The length of the clock timing unit is 1 millisecond ,clock()/CLOCKS_PER_SEC Is to convert milliseconds into seconds .

 

原网站

版权声明
本文为[Oh-liuxing]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140512081044.html