C++ 程序时间开销统计

 1 #include<iostream>
 2 #include<time.h>  //导入time库
 3 
 4 int main()
 5 {
 6     time_t start, end;  //定义两个time_t类型变量
 7     start = clock();   //记录程序起始时间
 8     //..程序..///
 9     end = clock();    //记录程序结束时间
10     cout << double(end - start) / CLOCKS_PER_SEC << "s" << endl;  //double(end-start)/CLOCKS_PER_SEC计算程序花销时间  CLOCKS_PER_SEC为time库内定义的常量,表示一秒内CPU运行的时钟周期数。
11     return 0;
12 }
原文地址:https://www.cnblogs.com/hl249853856/p/10133559.html