游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2884|回复: 5

如何知道一个程序的运算时间

[复制链接]

18

主题

82

帖子

86

积分

注册会员

Rank: 2

积分
86
发表于 2007-10-2 23:18:00 | 显示全部楼层 |阅读模式
如何知道一个程序的运算时间?有什么函数可用吗

0

主题

769

帖子

1052

积分

金牌会员

Rank: 6Rank: 6

积分
1052
发表于 2007-10-3 09:04:00 | 显示全部楼层

Re:如何知道一个程序的运算时间

timeGetTime()可以获取当前时间
然后去算应该可以吧

6

主题

46

帖子

46

积分

注册会员

Rank: 2

积分
46
发表于 2007-10-5 16:13:00 | 显示全部楼层

Re:如何知道一个程序的运算时间

int iNowTime = GetTickCount();
function()函数之类的操作
int iUseTime = GetTickCount()-iNowTime;
这样iUseTime就是执行的总时间

0

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2007-10-6 16:05:00 | 显示全部楼层

Re:如何知道一个程序的运算时间

摘取:http://bbs.pediy.com/showthread.php?t=51154

  1. QueryPerformanceCounter()采用3.579545MHZ计时器,精度能达到us.
  2. rdtsc取CPU内部time stamp counter,精度是ns级的。
  3. 你可以实测一下两段代码消耗的cpu周期数。


  4. // Win32, C++ return an int64, is EDX:EAX
  5. // rdtsc: 0F31
  6. __inline unsigned __int64 cput_64bit(void)
  7. {
  8.    __asm _emit 0x0F
  9.    __asm _emit 0x31
  10. }

  11. uint64 cpucnt_now;
  12. CRITICAL_SECTION  g_critical_cpu_cnt;

  13. InitializeCriticalSection(&g_critical_cpu_cnt);
  14. EnterCriticalSection(&g_critical_cpu_cnt);
  15. cpucnt_now = cput_64bit();
  16. // 待测代码段
  17. cpucnt_now = cput_64bit() - cpucnt_now;
  18. LeaveCriticalSection(&g_critical_cpu_cnt);
复制代码

6

主题

47

帖子

53

积分

注册会员

Rank: 2

积分
53
发表于 2007-10-6 17:38:00 | 显示全部楼层

Re: 如何知道一个程序的运算时间

BOOL GetProcessTimes(
  HANDLE hProcess,
  LPFILETIME lpCreationTime,
  LPFILETIME lpExitTime,
  LPFILETIME lpKernelTime,
  LPFILETIME lpUserTime
);

14

主题

251

帖子

251

积分

中级会员

Rank: 3Rank: 3

积分
251
发表于 2007-10-7 04:32:00 | 显示全部楼层

Re:如何知道一个程序的运算时间

叁楼正解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-15 11:35

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表