考虑:
#include <time.h>
#include <unistd.h>
#include <iostream>
using namespace std;
const int times = 1000;
const int N = 100000;
void run() {
for (int j = 0; j < N; j++) {
}
}
int main() {
clock_t main_start = clock();
for (int i = 0; i < times; i++) {
clock_t start = clock();
run();
cout << "cost: " << (clock() - start) / 1000.0 << " ms." << endl;
//usleep(1000);
}
cout << "total cost: " << …Run Code Online (Sandbox Code Playgroud) 使用排序的我的C程序第一次比其他时间慢了10倍.它使用整数文件进行排序,即使我更改数字,程序仍然运行得更快.当我重新启动PC时,第一次程序运行速度慢了10倍.我time用来计算时间.