Get clockcycles

psuter

New Member
I want to measure some modules in progress. But Etime() does not fullfill my wishes.
Is there a function in progess that gives me the processor cycles?

Pascal Suter
 

psuter

New Member
I've found the answer myself!

There is a Cyclecounter in kernel32.dll (windows api) that can be used instead of ETIME().

A call to the external function in kernel32.dll lasts about .92 ms. Therefore the exact time is between +/- 0.1 ms of the measured time:

DEFINE VARIABLE vLongOutMemptr AS MEMPTR NO-UNDO.

DEFINE VARIABLE viCyclesStart AS INTEGER NO-UNDO.
DEFINE VARIABLE viCyclesEnd AS INTEGER NO-UNDO.
DEFINE VARIABLE viFrequency AS INTEGER NO-UNDO.
DEFINE VARIABLE viCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE viLoops AS INTEGER NO-UNDO.

viLoops = 1.

/* define function-call to QueryPerformanceCounter in kernel32.dll */
PROCEDURE QueryPerformanceCounter EXTERNAL "kernel32.dll" PERSISTENT:
DEFINE OUTPUT PARAMETER vLongOutMemptr AS MEMPTR NO-UNDO.
END.

/* define function-call to QueryPerformanceFrequency in kernel32.dll */
PROCEDURE QueryPerformanceFrequency EXTERNAL "kernel32.dll" PERSISTENT:
DEFINE OUTPUT PARAMETER vLongOutMemptr AS MEMPTR NO-UNDO.
END.

/* reserve memoryspace of 8 Byte for variable of type LONG */
SET-SIZE(vLongOutMemptr) = 8.

/* call external function QueryPerformanceFrequency */
RUN QueryPerformanceFrequency(OUTPUT vLongOutMemptr).
viFrequency = GET-LONG(vLongOutMemptr, 1).

/* start measuring */
/* a function call lasts about 0.092 ms should be subtracted from result */
RUN QueryPerformanceCounter(OUTPUT vLongOutMemptr).
viCyclesStart = GET-LONG(vLongOutMemptr, 1).

DO viCounter = 1 TO viLoops:

END.

/* Stop measuring */
RUN QueryPerformanceCounter(OUTPUT vLongOutMemptr).
viCyclesEnd = GET-LONG(vLongOutMemptr, 1).

MESSAGE "Number of Cycles: " (viCyclesEnd - viCyclesStart) SKIP
"Frequency: " viFrequency SKIP
"Time [ms] per loop: " (viCyclesEnd - viCyclesStart) / viFrequency * 1000 / viLoops
VIEW-AS ALERT-BOX INFO BUTTONS OK.

/* release memory space */
SET-SIZE(vLongOutMemptr) = 0.

/* release kernel32.dll from memory */
RELEASE EXTERNAL PROCEDURE "kernel32.dll".
 
Top