测试程序运行所用的时间
测试程序运行所用的时间
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
clock_t start = clock();
long long s = 0;
for (long long i = 1; i <= 1000000000; i++)
{
s += i * i % 1000; // 加入一些计算,不要写简单的s++
//s++;
}
cout << "s is " << s << endl;
clock_t end = clock();
double duration = double(end - start) / CLOCKS_PER_SEC;
cout << "程序运行时间: " << duration << " 秒" << std::endl;
return 0;
}

浙公网安备 33010602011771号