这个时间代表多少?

loujing 2003-02-27 09:08:16
以前看一些程序设计比赛,要求程序运行时间少于1秒等等.
昨天自己写了一个,不知道对不对。
#include <time.h>
void main()
{
time_t start,finish;
start=clock();
//mycode
//
//
finish=clock();
cout<<finish-start<<endl;
}

运行结果,出现6149,我想知道这个6149代表什么意思?
还有,我这样写对不对,初学,望详解。
...全文
101 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
danmao 2003-02-27
  • 打赏
  • 举报
回复
/* 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 = 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() )
;
}
msdn上的源程序。很好懂吧?
windcsn 2003-02-27
  • 打赏
  • 举报
回复
代表你两次clock()运算之间的时间,和CLK_TCK的商就是秒数。
langzi8818 2003-02-27
  • 打赏
  • 举报
回复
关注中
luxc1972 2003-02-27
  • 打赏
  • 举报
回复
6149代表经过了多少个CLK_TCK, 6149/CLK_TCK就是经过的秒数,另外time_t和clock_t虽然都是long型,但clock()返加的是clock_t,所以建议你把start和finish定义为clock_t类型。

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧