» Home » VB Fibre
Site
News
Files

Visual Basic
Strings
Math
General
Properties
Memory
Methods

Search
Testing

Inline ASM-VB
Strings
Math
General
Memory

Search
Using inline ASM
Submit!

Accessing the high performance counter

The Performance Counter is a very high 64bit resolution counter
It's been in processors since the Intel 386. Note though, it doesn't return time.
It returns ticks (cycles)! To calculate it back to time you have to divide the ticks with the tick frequency of your computer. (you could use the queryperformancecounter API for it)

Most of the time you will only use the lower 32 bits. (the upper 32 bits are for long numbers only)


'//How-to use: This function returns the amounts of *ticks* in a 64bit number
'//You can simply use the CyclesLow for most measurements (which don't take too long)
'//
'// Dim lngCyclesHighStart As Long, lngCyclesLowStart As Long
'// Dim lngCyclesHighStop As Long, lngCyclesLowStop As Long
'//
'// Call MAsmCode.asmProcessorPerformance(lngCyclesHighStart, lngCyclesLowStart)
'//
'// '//Do something
'//
'// Call asmProcessorPerformance(lngCyclesHighStop, lngCyclesLowStop)
'//
'// Debug.Print = (lngCyclesLowStop - lngCyclesLowStart)
'//
'//Note: To convert to ms/ns, you'll need the frequency of the cpu.

Public Sub asmProcessorPerformance(ByRef CyclesHigh As Long, ByRef CyclesLow As Long)
'#ASM_START
'.586
' push ebp
' mov ebp, esp
' push edx
' push ecx
' push edi
'
' mov ecx, 0
' RDTSC

' mov edi, DWORD PTR [ebp+8]
' mov [edi], edx

' mov edi, DWORD PTR [ebp+12]
' mov [edi], eax

' pop edi
' pop ecx
' pop edx
' mov esp, ebp ;'//MOV/POP is much faster
' pop ebp ;'//on 486 and Pentium than Leave
' ret 4
'#ASM_END
End Sub


User contributed notes:

Author: CR () Date: 10:01 31/01/2006
How do you get the frequency of the CPU?

Add user-note
Author:
E-mail (optional):
Anti spam, please enter 'ok' without quotes:
Comment: