c++怎么取时钟?

「已注销」 2009-03-19 05:10:54
想计算程序运行的时间,一般在0.01秒一下

怎么样才可以记录呢?
怎么取时钟?
...全文
230 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
china_west 2009-03-25
  • 打赏
  • 举报
回复
就是,time
up
s79947171 2009-03-25
  • 打赏
  • 举报
回复

#include <iostream>
#include <ctime>
using namespace std;

int main()
{
clock_t start = clock();//开始时间
//运行程序.......
clock_t end= clock();//结束时间
int a =(end-start)/CLK_TCK;//结果为毫秒数
cout<<a<<endl;
return 0;
}

jakqigle 2009-03-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 fairchild811 的回复:]
GetTickCount
[/Quote]
up!
aaaa3105563 2009-03-24
  • 打赏
  • 举报
回复
SetTimer(hWnd,1,1000,NULL); //定时器
wangkeyunanjing 2009-03-24
  • 打赏
  • 举报
回复
ding
daiya81 2009-03-24
  • 打赏
  • 举报
回复
可以使用C语言的函数,头文件是<ctime>
参考:
http://hi.baidu.com/yanyan2006y/blog/item/ea28b28bfa5c05799e2fb4de.html
fairchild811 2009-03-19
  • 打赏
  • 举报
回复
GetTickCount
flameearth 2009-03-19
  • 打赏
  • 举报
回复
去搜索下关于 QueryPerformanceFrequency 这个因该可以
cppzhentan 2009-03-19
  • 打赏
  • 举报
回复
QueryPerformanceFrequency()
Dinelgua 2009-03-19
  • 打赏
  • 举报
回复
GetTickCount

The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. To obtain the system timer resolution, use the GetSystemTimeAdjustment function.


DWORD GetTickCount(void);

Parameters
This function has no parameters.
Return Values
The return value is the number of milliseconds that have elapsed since the system was started.

ppass 2009-03-19
  • 打赏
  • 举报
回复
在程序开始的时候取一次CPU时间,
在结束后再取一次,2者做差,将结果按要求转换即可,默认单位是毫秒好像是.
API不太记得了.找找.
tianma2005123 2009-03-19
  • 打赏
  • 举报
回复
timeGetTime()
QueryPerformanceFrequency()
downmooner 2009-03-19
  • 打赏
  • 举报
回复
#include<windows.h>

DWORD GetTickCount(void);
blingpro 2009-03-19
  • 打赏
  • 举报
回复
看一下多媒体定时器
pengzhixi 2009-03-19
  • 打赏
  • 举报
回复
那估计time满足不了你的要求了.

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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