C++中计算程序运行的时间

来源:互联网 发布:微软用的是windows系统 编辑:程序博客网 时间:2024/05/16 11:43

首先定义clock_t start, end;

然后在自己要测试那段代码的前面加上start = clock(); 结尾加上end = clock();

最后用输出语句进行

 cout<<"Run time: "<<(double)(end - start) / CLOCKS_PER_SEC<<"S"<<endl;
 cout<<"Run time: "<<(double)(end - start)<<"ms"<<endl;

0 0
原创粉丝点击