测试程序运行所用的时间

测试程序运行所用的时间

#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;
}

  

posted @ 2025-10-08 11:00  我微笑不代表我快乐  阅读(7)  评论(0)    收藏  举报