#define CLOCKS_PER_SEC = 1000000L;
CLOCKS_PER_SEC:它用来表示一秒钟会有多少个时钟计时单元
(float)(end - start) / CLOCKS_PER_SEC : 表示秒
(float)(end - start) / CLOCKS_PER_SEC * 1000 :表示毫秒
#include <iostream>
#include <time.h>
using namespace std;
int main(){
char buffer[100000] = {0};
clock_t start,end;
//start time
start = clock();
//to do...
for(int i = 0; i < sizeof(buffer); i++){
buffer[i] = i;
}
//end time
end = clock();
printf("data: total time = %fms\n",(float)(end - start) / CLOCKS_PER_SEC * 1000);
}
本文介绍C++中CLOCKS_PER_SEC宏定义的作用,解释了如何使用它来测量代码段的执行时间,包括将其转换为秒和毫秒的方法,并提供了一个具体的代码示例。
1254

被折叠的 条评论
为什么被折叠?



