clock,clock_t,times的注意事项
来源:互联网 发布:sql自定义函数编写 编辑:程序博客网 时间:2024/05/18 12:37
1. clock,windows下的time一样, 也和 linux下的times一样
2. clock返回clock_t型,其实就是长整型
3. clock和times返回的单位是滴答
4. 滴答根据不同的系统,和不同的标准而不同
The clock() function returns the processor time since the program started, or -1 if that information is unavailable. To convert the return value to seconds, divide it by CLOCKS_PER_SEC.(windows)
times 和 clock都收用来计算cpu时间。times函数的返回值是进程迄今为止的存活时间。所有时间都是以“滴答”为单位的,linux系统下,函数 sysconf(_SC_CLK_TCK)可获得所运行系统每秒的滴答数。
typedef long clock_t;
//windows#include <stdio.h>#include <time.h>int main(){printf("%ld\n", CLOCKS_PER_SEC);return 0;}
输出结果为:1000
//Ubuntu#include <stdio.h>#include <unistd.h>#include <sys/times.h>int main(int argc, char* argv[]){int sec_per_dida = sysconf( _SC_CLK_TCK);printf("%d\n", sec_per_dida);return 0;}
输出结果为:100
time的例子:
#include <stdio.h>#include <windows.h>#include <time.h>int main(){long beg;long end;beg = time(0);Sleep(5000);end = time(0);printf("%ld\n", end - beg);return 0;}
输出结果为5,可知time返回的单位是滴答。
- clock,clock_t,times的注意事项
- 关于time_t,clock_t ,time(),clock(),CLK_TCK, CLOCKS_PER_SEC 的使用
- 关于time_t,clock_t ,time(),clock(),CLK_TCK, CLOCKS_PER_SEC 的使用
- [DirectShow] 021 - Clock Times
- clock time times
- clock 、times 、gettimeofday
- C/C++中的计时函数是clock(),而与其相关的数据类型是clock_t。
- 处理器时间函数 clock_t clock( void );
- c++中计算运行时间 clock(),clock_t程序
- clock_t与time_t的区别
- c++中计算运行时间 clock() clock_t 示例:比较递归和非递归数值运算
- c++中计算运行时间 clock() clock_t 示例:比较递归和非递归数值运算
- c++中计算运行时间 clock() clock_t 示例:比较递归和非递归数值运算
- clock_t与time_t的区别及联系
- clock_t与time_t的区别及联系
- clock_t实际类型的查找流程
- times系统调用的例子
- android-times-square的使用
- matlab GUI callback 函数实现
- NYOJ-467 中缀式变后缀式【逆波兰法】
- C语言的变量声明在其它语句之前
- 对用户的密码进行加密
- hdoj 1142 A Walk Through the Forest
- clock,clock_t,times的注意事项
- HDU 1241Oil Deposits
- window.open()详细解释
- FVWM简明使用指南——王垠
- JDom解析xml(一)
- python写的sogou代理全网加速器两个注意的
- 第5周实验报告任务2
- Python脚本转可执行程序cx_Freeze
- 第五周C++作业 报告一。