| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 514 人关注过本帖
标题:[求助]关于计时
只看楼主 加入收藏
realoneyjw
Rank: 1
等 级:新手上路
帖 子:99
专家分:0
注 册:2005-5-13
收藏
 问题点数:0 回复次数:3 
[求助]关于计时

请问一下,c++中有没有类似matlab中一样可以给程序的运行时间计时的功能?

如果有的话麻烦给个例子在此先行谢过了!

搜索更多相关主题的帖子: 计时 
2006-04-07 10:51
gototheworld
Rank: 1
等 级:新手上路
帖 子:218
专家分:0
注 册:2006-3-24
收藏
得分:0 

这个当然有了


路漫漫其修远兮 吾将上下而求索
2006-04-07 12:18
gototheworld
Rank: 1
等 级:新手上路
帖 子:218
专家分:0
注 册:2006-3-24
收藏
得分:0 

给你例子
// crt_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 );

int main( void )
{
long i = 6000000L;
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 );
return 0;
}

// Pauses for a specified number of milliseconds.
void sleep( clock_t wait )
{
clock_t goal;
goal = wait + clock();
while( goal > clock() )
;
}


路漫漫其修远兮 吾将上下而求索
2006-04-07 12:20
realoneyjw
Rank: 1
等 级:新手上路
帖 子:99
专家分:0
注 册:2005-5-13
收藏
得分:0 
谢谢了

我一直告诫自己:要做一个踏实认真的人 E-mail:realoneyjw@ qq:18238423
2006-04-07 15:34
快速回复:[求助]关于计时
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017843 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved