程序执行时间计算问题

vckko 2010-03-07 01:10:51
找了些贴都是在程序上加时间计算函数.
那些程序比赛如CODEJAM ACM等都是怎么样计算的?要用什么软件吗?
...全文
83 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2010-03-09
  • 打赏
  • 举报
回复
你百度一下,可以直接输出执行时间的
很简单的
Crob 2010-03-07
  • 打赏
  • 举报
回复
unix或linux下用times函数

#include <sys/times.h>
clock_t times(struct tms *buf);

可以得到 cpu time,user time
lovesi3344 2010-03-07
  • 打赏
  • 举报
回复
#include<iostream> 
include<windows.h>
using namespace std;
int main()
{
DWORD start_time=GetTickCount();
{
//此处为被测试代码
}
DWORD end_time=GetTickCount();
cout<<"The run time is:"<<(end_time-start_time)<<"ms!"<<endl;//输出运行时间
return 0;
}

#include<iostream>
#include<time.h>
using namespace std;
int main()
{
clock_t start_time=clock();
{
//被测试代码
}
clock_t end_time=clock();
cout<< "Running time is: "<<static_cast<double>(end_time- start_time)/CLOCKS_PER_SEC*1000<<"ms"<<endl;//输出运行时间
return 0;
}
#include<iostream> 
#include<ctime>
using namespace std;
int main()
{
time_t begin,end;
begin=clock();
//这里加上你的代码
end=clock();
cout<<"runtime: "<<double(end-begin)/CLOCKS_PER_SEC<<endl;
return 0;
}
2010-03-07
  • 打赏
  • 举报
回复
       #include <sys/times.h>

clock_t times(struct tms *buf);

struct tms {
clock_t tms_utime; /* 用户时间 */
clock_t tms_stime; /* 系统时间 */
clock_t tms_cutime; /* 子进程的用户时间 */
clock_t tms_cstime; /* 子进程的系统时间 */
};

struct tms 里面后两个是指已经回收的子进程消耗的时间。
linglongyouzhi 2010-03-07
  • 打赏
  • 举报
回复
应该类似的,不过好像unix类的操作系统是有相应的应用程序的

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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