This is a test piece for a late Win 10 API function, QueryUnbiasedInterruptTime. It is supposed to have slightly better precision due to not counting system delays.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include64\masm64rt.inc
.data?
QueryUnbiasedInterruptTime dq ?
.code
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
entry_point proc
USING r12,r13
LOCAL krnl :QWORD
LOCAL rslt1 :REAL8
LOCAL rslt2 :REAL8
LOCAL var :REAL8
LOCAL text :QWORD
LOCAL buff[64]:BYTE
LOCAL pbuf :QWORD
SaveRegs
HighPriority
sas text,"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
mov krnl, rvcall(GetModuleHandle,"kernel32.dll")
mov QueryUnbiasedInterruptTime, rvcall(GetProcAddress,krnl,"QueryUnbiasedInterruptTime")
conout "Output is in seconds",lf,lf
mov pbuf, ptr$(buff) ; get pointer to buffer
mov r12, 10 ; the iteration counter
; *********************************
lbl:
rcall QueryUnbiasedInterruptTime,ptr$(rslt1)
cpuid
; =================================
mov r13, 80000000 ; inner loop counter
cnlp:
; ---------------------------------
rcall StrLen,text ; time StrLen algorithm
; ---------------------------------
sub r13, 1
jnz cnlp
; =================================
rcall QueryUnbiasedInterruptTime,ptr$(rslt2)
mov rax, rslt1 ; sub result 1 from result 2
sub rslt2, rax
cvtsi2sd xmm0, rslt2 ; convert into to scalar double
divsd xmm0, AFL8(10000000.0) ; divide result by 10 million to get seconds
movsd var, xmm0 ; store the result in the REAL8 variable
rcall fptoa,var,pbuf ; convert result to string
rcall truncate,pbuf,6 ; truncate decinal places
conout " ",pbuf,lf ; display result
sub r12, 1
jnz lbl
; *********************************
conout lf,"Thats all folks ....",lf,lf
NormalPriority
waitkey
RestoreRegs
.exit
entry_point endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end