Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1121640
  • 博文数量: 82
  • 博客积分: 3362
  • 博客等级: 中校
  • 技术积分: 500
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-05 16:27
文章分类

全部博文(82)

文章存档

2011年(1)

2010年(19)

2009年(62)

我的朋友

分类: C/C++

2010-02-19 12:50:42

MSDN clock

经常忘记写一下:

Example

/* CLOCK.C: This example prompts for how long
* the program is to run and then continuously
* displays the elapsed time for that period.
*/
#include 
#include 
#include 
void sleep( clock_t wait );
void main( void )
{
  long    i = 600000L;
  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() )
     ;
}

Output

Delay for three seconds
Done!
Time to do 600000 empty loops is 0.1 seconds
阅读(275) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~