如何计算一个程序的运行时间

时间:2022-07-24
本文章向大家介绍如何计算一个程序的运行时间,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
#include<iostream.h>
 #include<time.h>
 void main()
 {
 clock_t start,finish;
 double totaltime;
 start=clock();
…… //把你的程序代码插入到这里面
finish=clock();
 totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
 cout<<"n此程序的运行时间为"<<totaltime<<“秒!”<<endl;
 }