c语言clock函数使用示例

 更新时间:2014年04月01日 16:14:01   作者:  
这篇文章主要介绍了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语言中字符的输入输出以及计算字符个数的方法,是C语言入门学习中的基础知识,需要的朋友可以参考下
    2015-11-11
  • C语言超详细讲解排序算法上篇

    C语言超详细讲解排序算法上篇

    时间如流水,今天就到初阶数据结构最后一个知识章节了,常见的排序算法!在进入这期之前,程爱打篮球的程序猿想说一句,如果有不懂的地方可以反复观看我之前的内容,再还有不懂可以直接找我,帮你安排的妥妥的
    2022-03-03
  • C++:函数对象,STL提供的函数对象,函数适配器详解

    C++:函数对象,STL提供的函数对象,函数适配器详解

    这篇文章主要介绍了C++:函数对象,STL提供的函数对象,函数适配器的使用详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-08-08
  • C++冒泡排序算法实例

    C++冒泡排序算法实例

    这篇文章主要介绍了C++冒泡排序算法实例,本文先是介绍了什么是冒泡排序,然后给出了实现代码,需要的朋友可以参考下
    2014-10-10
  • C语言数据结构与算法之链表(一)

    C语言数据结构与算法之链表(一)

    链表是线性表的链式存储方式。链表的内存是不连续的,前一个元素存储地址的下一个地址中存储的不一定是下一个元素。小编今天就将带大家深入了解一下链表,快来学习吧
    2021-12-12
  • C语言中的各种文件读写方法小结

    C语言中的各种文件读写方法小结

    这篇文章主要介绍了C语言中的各种文件读写方法小结,是C语言入门学习中的基础知识,需要的朋友可以参考下
    2015-07-07
  • C语言递归:汉诺塔问题分析

    C语言递归:汉诺塔问题分析

    这篇文章主要介绍了C语言递归:汉诺塔问题分析的相关资料,需要的朋友可以参考下
    2023-01-01
  • C++归并排序算法实例

    C++归并排序算法实例

    这篇文章主要介绍了C++归并排序算法实例,本文先是介绍了什么是归并排序,然后给出了实现代码,需要的朋友可以参考下
    2014-10-10
  • C语言实现数字雨效果

    C语言实现数字雨效果

    这篇文章主要为大家详细介绍了C语言实现数字雨效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-02-02
  • C语言printf详细解析

    C语言printf详细解析

    C中格式字符串printf()的一般形式为: %[标志][输出最小宽度][.精度][长度]类型, 其中方括号[]中的项为可选项。各项的意义介绍如下
    2013-09-09

最新评论