C++利用C语言的time库, 即可统计措施的运行时间;
头文件#include <ctime>
代码:
#include<iostream>
#include<ctime>
void do_something()
{
for(int i=0;i<100000;i++)
for(int j=0;j<10000;j++)
;
}
int main(int arg,char ** argv)
{
clock_t start = clock();
do_something();
clock_t end = clock();
double time = static_cast<double>(end-start)/CLOCKS_PER_SEC;
std::cout << "time = " << time << std::endl;
return 0;
}
