c语言clock函数使用示例
clock_t clock( void );
Calculates the processor time used by the calling process
head file is <time.h>
Return Value
clock returns the number of clock ticks of elapsed processor time. The returned value
is the product of the amount of time that has elapsed since the start of a process and
the value of the CLOCKS_PER_SEC constant. If the amount of elapsed time is
unavailable, the function returns –1, cast as a clock_t.
Remarks
The clock function tells how much processor time the calling process has used. The
time in seconds is approximated by dividing the clock return value by the value of the
CLOCKS_PER_SEC constant. In other words, clock returns the number of
processor timer ticks that have elapsed. A timer tick is approximately equal to
1/CLOCKS_PER_SEC second. In versions of Microsoft C before 6.0, the
CLOCKS_PER_SEC constant was called CLK_TCK.
/* CLOCK.C: This example prompts for how long
* the program is to run and then continuously
* displays the elapsed time for that period.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sleep( clock_t wait );
void main( void )
{
long i = 600000000L;
clock_t start, finish;
double duration;
/* Delay for a specified time. */
printf( "Delay for three seconds\n" );
sleep( (clock_t)3 * CLOCKS_PER_SEC );
printf( "Done!\n" );
/* Measure the duration of an event. */
printf( "Time to do %ld empty loops is ", i );
start = clock();
while( i-- )
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%2.1f seconds\n", duration );
}
/* Pauses for a specified number of milliseconds. */
void sleep( clock_t wait )
{
clock_t goal;
goal = wait + clock();
while( goal > clock() )
}//sleep
上一篇:四叉树有损位图压缩处理程序示例
栏 目:C语言
下一篇:C语言中的回调函数实例
本文标题:c语言clock函数使用示例
本文地址:https://www.xiuzhanwang.com/a1/Cyuyan/3698.html
您可能感兴趣的文章
- 04-02c语言函数调用后清空内存 c语言调用函数删除字符
- 04-02c语言的正则匹配函数 c语言正则表达式函数库
- 04-02func函数+在C语言 func函数在c语言中
- 04-02c语言中对数函数的表达式 c语言中对数怎么表达
- 04-02c语言用函数写分段 用c语言表示分段函数
- 04-02c语言编写函数冒泡排序 c语言冒泡排序法函数
- 04-02c语言没有round函数 round c语言
- 04-02c语言分段函数怎么求 用c语言求分段函数
- 04-02C语言中怎么打出三角函数 c语言中怎么打出三角函数的值
- 04-02c语言调用函数求fibo C语言调用函数求阶乘
阅读排行
本栏相关
- 04-02c语言函数调用后清空内存 c语言调用
- 04-02func函数+在C语言 func函数在c语言中
- 04-02c语言的正则匹配函数 c语言正则表达
- 04-02c语言用函数写分段 用c语言表示分段
- 04-02c语言中对数函数的表达式 c语言中对
- 04-02c语言编写函数冒泡排序 c语言冒泡排
- 04-02c语言没有round函数 round c语言
- 04-02c语言分段函数怎么求 用c语言求分段
- 04-02C语言中怎么打出三角函数 c语言中怎
- 04-02c语言调用函数求fibo C语言调用函数求
随机阅读
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 01-10SublimeText编译C开发环境设置
- 01-10delphi制作wav文件的方法
- 01-11ajax实现页面的局部加载
- 04-02jquery与jsp,用jquery
- 01-10C#中split用法实例总结
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 08-05织梦dedecms什么时候用栏目交叉功能?