Author Topic: Adamanteus milliseconds code timing macros  (Read 4471 times)

Adamanteus

  • Member
  • **
  • Posts: 180
Adamanteus milliseconds code timing macros
« on: May 24, 2012, 04:41:03 AM »
This alternative is  :t a reposting from the old forum

jj2007

  • Member
  • *****
  • Posts: 7548
  • Assembler is fun ;-)
    • MasmBasic
Re: Adamanteus milliseconds code timing macros
« Reply #1 on: May 24, 2012, 05:26:47 AM »
Can you give a little example how to use it, like below?

include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   NanoTimer()
   invoke Sleep, 500
   Inkey Str$("Your puter slept for %8f µs", NanoTimer(µs))
   Exit
end start

Output: Your puter slept for 500015.00 µs

Adamanteus

  • Member
  • **
  • Posts: 180
Re: Adamanteus milliseconds code timing macros
« Reply #2 on: May 24, 2012, 03:35:03 PM »
Code: (asm) [Select]
include masm32rt.inc
.586

CORRELATION EQU 14 ; correlation time in ticks
;COUNTTICKS EQU 1 ; use ticks counting
;DBGTIMING EQU 1 ; check for correct correlation
;WIN EQU 1 ; for windowed interface

include timing.mac

.DATA

ifDef WIN
string db 40 dup(?)
Endif

ms DD ?
ns DD ?

.STACK

.CODE

ifDef WIN

Start:

start_timing

invoke Sleep, 500

stop_timing , ms, ns

invoke wsprintf, ADDR string, chr$("%u ms %d ns"), ms, ns

invoke MessageBox, NULL, ADDR string, chr$("Sleep(500)"), MB_OK or MB_ICONASTERISK

invoke ExitProcess, NULL

Else

Start:

start_timing

invoke Sleep, 500

stop_timing "Sleep(500)"

invoke ExitProcess, NULL

Endif

END Start

Output : Sleep(500)      : 5150 ms -276 ns - if nanoseconds is negative, them need to subtract, so 5149 ms 724 ns

CORRELATION possible determine with DBGTIMING - need result is more near to zero nanoseconds.
If ticks is not fit to given range, after get counter is need to divide to 10 sometime (it's depends on Windows build version, mostly not need)