数据结构和算法01--时间计量方法

  在windows平台,使用3大常用计量方法:

1:GetTickCount

2:timeGetTime  1ms

3:QueryPerformanceCount  和系统有关,大概在100ns

4:RDTSC      1ns

 

  同样在linux下

times

clock

RDTSC

 

  本文将使用RDTSC,由于不依赖windows API.

需要注意的是,即使使用RDTSC,在很短的时间间隔下,依然是没有意义的,多任务的特性,使<1ms甚至10ms的误差都会出现.所以在计量的时候会尽量采用大的循环和样本减少误差.

 

参考http://blog.csdn.net/immortal_06/archive/2008/05/08/2415568.aspx

 

另外:

Windows下的其它一些探讨:

 

参考:

1:The Performance of Every Day Things Jeffrey Richter

http://www.cnblogs.com/JeffreyZhao/archive/2009/03/10/codetimer.html

http://www.cnblogs.com/eaglet/archive/2009/03/10/1407791.html

http://blog.csdn.net/eaglet/archive/2009/05/25/4213550.aspx

http://blog.kalmbachnet.de/?postid=28

c#的performace工具 QueryThreadCycleTime QueryProcessCycleTime vista及其以上

GetThreadTimes vista及其以下(在线程切换频繁的时候,计数错误)

 

2:http://www.fjsnow.com/tcbbs/archiver/?tid-661.html

此篇文章说明RDTSC是和硬件和运行状态相关的,QueryPerformanceCount也是,所以测试必须在统一状态下测试. 比如一直是非节能模式,使用SetThreadAffinityMask使程序运行在一个CPU上...这才有意义.

 

posted @ 2009-11-20 10:19  vcommon  阅读(238)  评论(0编辑  收藏  举报