📄 cputime.c
字号:
/* Copyright (c) Colorado School of Mines, 1990./* All rights reserved. */#include <time.h>/* ANSI C book says clock() units are CLK_TCK, but IBM docs say millisecs */#ifdef _IBMR2#define CLOCK_UNIT 1000000#else/* #define CLOCK_UNIT CLK_TCK */#define CLOCK_UNIT 1000000 /* SUN uses microseconds */#endiffloatcputime()/*****************************************************************************return cpu time (UNIX user time) in seconds using ANSI C built-ins******************************************************************************Author: Jack K. Cohen, Colorado School of Mines, 07/27/90*****************************************************************************/{ return clock() / (float) CLOCK_UNIT;}#ifdef TESTmain(){ int i, n = 1000000; float cpu_used, a = 0.0, b = 1.0; cpu_used = cputime(); for (i = 0; i < n; ++i) a += b; cpu_used = cputime() - cpu_used; printf("a = %f cpu time = %f\n", a, cpu_used);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -