栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c语言clock函数使用示例

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c语言clock函数使用示例

clock_t clock( void );
Calculates the processor time used by the calling process
head file is

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.

复制代码 代码如下:

#include
#include
#include
void sleep( clock_t wait );
void main( void )
{
   long    i = 600000000L;
   clock_t start, finish;
   double  duration;
  
   printf( "Delay for three secondsn" );
   sleep( (clock_t)3 * CLOCKS_PER_SEC );
   printf( "Done!n" );
  
   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 secondsn", duration );
}

void sleep( clock_t wait )
{
   clock_t goal;
   goal = wait + clock();
   while( goal > clock() )

}//sleep

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/65785.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号