Cro*_*ity 5 c macos time clock
#import <stdio.h>
#import <time.h>
int main (void) {
printf("Clock ticks per second: %d\n", CLOCKS_PER_SEC);
double check = clock();
int timex = time(NULL);
for (int x = 0; x <= 500000; x++) {
printf(".");
}
puts("\n");
printf("Total Time by Clock: %7.7f\n", (clock() - check) / CLOCKS_PER_SEC );
printf("Total Time by Time: %d\n", time(NULL) - timex);
getchar();
}
Run Code Online (Sandbox Code Playgroud)
当我执行上面的代码时,我得到的结果如下:
时钟总时间:0.0108240
总时间:12
我想让clock()代表一个尽可能接近时间的数字.
上面给出的总时间是在macbook上完成的,但是,我的笔记本电脑(windows)上的代码效果非常好.
CLOCKS_PER_SECOND宏在PC上返回1000,在MAC上返回1,000,000.
| 归档时间: |
|
| 查看次数: |
800 次 |
| 最近记录: |