一个计算程序运行耗时的代码段
1#include "time.h"
2
3// 时间变量与时间函数
4clock_t tstart = 0;
5
6
7void Settime()
8 {
9 tstart = clock();
10}
11
12
13double Gettime()
14 {
15 return (double)((double)clock() - (double)tstart)/(double)CLOCKS_PER_SEC;
16}
17
18
19
20int main()
21{
22 Settime();//开始计时
23 /****
24 do something ****/
25
26 cout << "-->监视耗时 : " ;
27 cout << Gettime()<< endl ;
28
29 return 1;
30}
2
3// 时间变量与时间函数
4clock_t tstart = 0;
5
6
7void Settime()
8 {
9 tstart = clock();
10}
11
12
13double Gettime()
14 {
15 return (double)((double)clock() - (double)tstart)/(double)CLOCKS_PER_SEC;
16}
17
18
19
20int main()
21{
22 Settime();//开始计时
23 /****
24 do something ****/
25
26 cout << "-->监视耗时 : " ;
27 cout << Gettime()<< endl ;
28
29 return 1;
30}