首页 > 其他分享 >C语言学习:计算时间差

C语言学习:计算时间差

时间:2023-02-12 13:44:06浏览次数:45  
标签:end clock DoHardWork 时间差 学习 start time PRINT C语言

 

 1 #include <io_utils.h>
 2 #include <time_utils.h>
 3 #include <time.h>
 4 
 5 #define PI 3.1415926
 6 
 7 void DoHardWork() {
 8   double sum = 0;
 9   for (int i = 0; i < 10000000; ++i) {
10     sum += i * i / PI;
11   }
12   PRINT_DOUBLE(sum);
13 }
14 
15 int main() {
16   time_t start_time = time(NULL);
17   DoHardWork();
18   time_t end_time = time(NULL);
19   double diff = difftime(start_time, end_time);
20   PRINT_DOUBLE(diff);
21 
22   long_time_t start_time_ms = TimeInMillisecond();
23   DoHardWork();
24   long_time_t end_time_ms = TimeInMillisecond();
25   PRINT_LLONG(end_time_ms - start_time_ms);
26 
27   clock_t start_time_c = clock();
28   DoHardWork();
29   clock_t end_time_c = clock();
30   PRINT_DOUBLE((end_time_c - start_time_c) * 1.0 / CLOCKS_PER_SEC);
31   return 0;
32 }
View Code

 

 

 

标签:end,clock,DoHardWork,时间差,学习,start,time,PRINT,C语言
From: https://www.cnblogs.com/liumy/p/17113719.html

相关文章