Getting more accurate timer values …

Windows has support for 64bit timers – giving you the chance to have a more accurate timing source. Here is a source code example to use the available API calls:

frequency := OSUInt64 new.
firstTick := OSUInt64 new.
secondTick := OSUInt64 new.
(PlatformFunctions::QueryPerformanceFrequency callWith: frequency)
  ifTrue:[
   (PlatformFunctions::QueryPerformanceCounter callWith: firstTick)
     ifTrue:[
      (PlatformFunctions::QueryPerformanceCounter callWith: secondTick)
        ifTrue:[ Transcript cr ; show: 'Overhead API call:',(((secondTick at: 0) - (firstTick at: 0)) / (frequency at: 0)) asFloat asString,' in sec' ]
        ifFalse:[ Transcript cr ; show: 'Error retrieving secondTick :',MSKOperatingServices GetLastErrorMessageOrNil asString ]]
      ifFalse:[ Transcript cr ; show: 'Error retrieving firstTick :',MSKOperatingServices GetLastErrorMessageOrNil asString ]]
  ifFalse:[ Transcript cr ; show: 'Error retrieving frequency value :',MSKOperatingServices GetLastErrorMessageOrNil asString ]

On my machine (2.6 GHz – Windows XP, Intel Dual-Core) I get an API overhead time of about 3.5 * 10^-7 seconds, when changing the last both callWith to asyncCallWith: I will get 2 * 10^-5 seconds for each call – meaning,that the asyncCall is 100 times more expensive than the synchronous callWith call.

On my home machine (2.2 GHz – W7/64, Quad-Core) I get 5*10^-5 sec for asyncCall and 9.3*10^-7 sec for syncCalls …

For more information about this API you may read here or here

This entry was posted in Smalltalk. Bookmark the permalink.