c++计时函数

clock函数

#include <iostream>
#include <ctime> //要包含的头文件
using namespace std;
int main()
{
   double startTime = clock();
   for(int i = 0; i < 214748364; i++);
   double endTime = clock();
   cout << "The run time is: " <<(double)(endTime - startTime) / 1000 << "s" << endl;

    return 0;
}

GetTickCount()函数

#include <iostream>
#include<Windows.h> //要包含的头文件
using namespace std;
int main()
{
    double startTime = GetTickCount();//计时开始
   for(int i = 0; i < 214748364; i++);
   double endTime = GetTickCount();//计时结束
   cout << "The run time is:" << endTime - startTime << "ms" << endl;

    return 0;
}

详细用法---->>点我

Java中计时函数----->点我

猜你喜欢

转载自blog.csdn.net/qq_40794973/article/details/81607896