News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Timer Macros

Started by Gunther, February 04, 2021, 07:35:22 PM

Previous topic - Next topic

Gunther

Under MASM32 SDK we had nifty timer macros (I think Michael W. wrote those). Is there something comparable for Win64?

Gunther
You have to know the facts before you can distort them.

jj2007

Use QueryPerformanceCounter, it's the best option

TimoVJL

A useless loop before timing should wake up CPU to full speed.
A one AMD was running at speed 800 MHz before tests.
May the source be with you

hutch--

Timo is right, my old i7 used to idle at 1.2 gig and under load 3.3 gig and it was not until I clocked it to a higher frequency that it stabilised. The trick was to run the code once then clock the rest. Michael's code used to work well but when CPUs started to run variable clock speeds, especially on different cores it no longer worked well.

jj2007

Counting cycles rarely makes sense. The M$ recommended way to time algos is QueryPerformanceCounter:

include \Masm32\MasmBasic\Res\JBasic.inc ; ## builds in 32- or 64-bit mode with UAsm, ML, AsmC ##
MbNanoStart QWORD ?
MbNanoEnd QWORD ?
MbNanoSecs QWORD ?
MbNanoFreq QWORD ?
Init ; OPT_64 1 ; put 0 for 32 bit, 1 for 64 bit assembly
  PrintLine Chr$("This program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
  jinvoke QueryPerformanceCounter, offset MbNanoStart
  jinvoke Sleep, 1000
  jinvoke QueryPerformanceCounter, offset MbNanoEnd
  fild MbNanoEnd
  fild MbNanoStart
  fsub
  fld st
  jinvoke QueryPerformanceFrequency, offset MbNanoFreq
  fild MbNanoFreq
  fdiv
  fmul FP4(1000.0)
  fistp MbNanoSecs
  Inkey Str$("The Sleep(1000) took %lu milliseconds", MbNanoSecs)
EndOfCode


Output:
This program was assembled with ml64 in 64-bit format.
The Sleep(1000) took 999 milliseconds

mikeburr

0F31 from memory
regards mike b

Gunther

Thank you for all the advice given.  :thumbsup: I'll think about it and believe that I can solve my problem.

Gunther
You have to know the facts before you can distort them.