用clock函数统计运行时间。
下面程序中的for语句,循环次数是n。
#include <bits/stdc++.h>
using namespace std;
int main(){
int i,k;
int n=1e8;
clock_t start, end;
start = clock();
for(i = 0; i < n; i++)
k++;
end = clock();
cout << (double)(end - start) / CLOCKS_PER_SEC << endl;
}