#include<stdio.h>
#include<time.h>
#include<iostream>
using namespace std;
clock_t start, stop;
double duration;
void ls(int n);
int main()
{
start = clock();
ls(10);
stop = clock();
duration = ((double)(stop - start)) / CLK_TCK;
cout <<" 用时:"<<duration << endl;
system("pause");
return 0;
}
void ls(int n)
{
for (int i = 0; i < n; i++)
{
cout << i << endl;
}
#include<time.h>
#include<iostream>
using namespace std;
clock_t start, stop;
double duration;
void ls(int n);
int main()
{
start = clock();
ls(10);
stop = clock();
duration = ((double)(stop - start)) / CLK_TCK;
cout <<" 用时:"<<duration << endl;
system("pause");
return 0;
}
void ls(int n)
{
for (int i = 0; i < n; i++)
{
cout << i << endl;
}
}
注意:如何测出不到1个tick的程序运行时间?
答案是:重复