第一种方法:
# include "time.h"
void main()
{
clock_t start_time, end_time;
start_time = clock(); //获取开始执行时间
xxxxxxx; //过程
end_time = clock(); //获取结束时间
double Times = (double)(end_time - start_time) / CLOCKS_PER_SEC;
printf("%f seconds\n", Times);
}
第二种方法:
1 #include<iostream>
2 #include<Windows.h>
3 using namespace std;
4 int main()
5 {
6 DWORD startTime = GetTickCount();//计时开始
7 for (int i = 0; i < 2147483640; i++)
8 {
9 i++;
10 }
11 DWORD endTime = GetTickCount();//计时结束
12 cout << "The run time is:" << endTime - startTime << "ms" << endl;
13 system("pause");
14 return 0;
15 }