社区
C语言
帖子详情
这个时间代表多少?
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代表什么意思?
还有,我这样写对不对,初学,望详解。
...全文
122
4
打赏
收藏
这个时间代表多少?
以前看一些程序设计比赛,要求程序运行时间少于1秒等等. 昨天自己写了一个,不知道对不对。 #include void main() { time_t start,finish; start=clock(); //mycode // // finish=clock(); cout<<finish-start<<endl; } 运行结果,出现6149,我想知道这个6149代表什么意思? 还有,我这样写对不对,初学,望详解。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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类型。
Java问题宝典2012版
38、try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,在return前还是后? 27 39、下面的程序代码输出的结果是多少? 28 40、final, finally, finalize的区别。 30 ...
你必须知道的495个C语言问题
第1章 声明和初始化 ...6.23 sizeof返回的大小是以字节计算的,怎样才能判断数组中有多少个元素呢? 第7章 内存分配 基本的内存分配问题 7.1 为什么这段代码不行?char*answer;printf("Typesomething...
python中%
代表
什么意思?
python中%
代表
什么意思?
泛型中? super T和? extends T的理解
这个玩意有什么用呢,起到限定作用,比如你要实现一个list集合拷贝的方法,即Collect.copy(listD,listS); 如果不加任何限制,那么任何类型的两个List都能进行拷贝肯定是不正确的,因为里面的字段千差万别。 假设ListD...
c语言pl是什么意思,相机中PL,ND各
代表
什么?
相机中PL,ND各
代表
什么?以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!相机中PL,ND各
代表
什么?PL,ND在相机中都
代表
滤光。1:PL
代表
的是相机的...
C语言
70,037
社区成员
243,245
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章