_RDTSC Function

Purpose

Returns the number of processor cycles.

Syntax

x = _RDTSC

x : int64

Description

With the function _RDTSC it is possible to determine how many cycles your program needs to do something by calling the state of the Time Stamp Counter (TSC).

Example

OpenW 1

Local Large l1, l2, l3, l4

Local i As Large, x%

For i = 1 To 20

l1 = _RDTSC : l2 = _RDTSC

l3 = _RDTSC : l4 = _RDTSC

Print l2 - l1; l3 - l2; l4 - l3

Next

Do : Sleep : Until Win_1 Is Nothing

Remarks

Since the introduction of the Pentium, the processor provides the cycle counter in an internal 64-bit register. The counter is reset each time the computer is switched on.

Example

$StepOff

OpenW 1

Global a$, l As Large, s$, sum As Int, t As Double

Local i As Register Int

Print

s$ = Space$(100000)

t = Timer : l = _RDTSC : sum = 0

For i = 1 To Len(s$)

a$ = Mid$(s$, i, 1)

sum += Asc(a$)

Next

l = _RDTSC - l : t = Timer - t

Print "Number of cycles: "; l

Print "Time in seconds: "; t

Do :   Sleep : Until Me Is Nothing

See Also

Timer, $StepOff, Naked

{Created by Sjouke Hamstra; Last updated: 13/06/2022 by James Gaite}