1、clock函数----返回CPU计时单元。函数返回开启这个程序进程到程序中调用clock函数时之间的CPU时钟计时单元(返回毫秒)。 (计的是占用cpu的时间)
函数原型:long clock();
函数参数:无参数
关联:CLOCKS_PER_SEC 在time.h中有宏定义 表示1秒钟有1000个计时单元 每过1毫秒 clock函数的返回值就会增加1. clock()/CLOCKS_PER_SEC 表示一个进程自身的运行时间。
用例:
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
long n=0;
clock_t start,finish; ////定义两个可以保存clock()的变量
start=clock();
while(n<1000000000)
n++;
finish=clock();
cout<<(finish-start)/CLOCKS_PER_SEC<<endl;
return 0;
}
1、time函数----返回CPU计时单元。函数返回开启这个程序进程到程序中调用clock函数时之间的CPU时钟计时单元(返回毫秒)。 (计的是占用cpu的时间)
函数原型:long clock();
函数参数:无参数