Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
' Place this code in any Sub or Function
Dim lngStart As Long
Dim lngFinish As Long
Dim lngCounter As Long
Dim varArr As Variant
Dim strArr(2) As String
'TEST1
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounter = 1 To 100000
varArr = Array("A", "B", "C")
Next
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
Debug.Print "Test 1: " & CStr(lngFinish - lngStart)
'TEST2
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounter = 1 To 100000
strArr(0) = "A"
strArr(1) = "B"
strArr(2) = "C"
Next
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
Debug.Print "Test 2: " & CStr(lngFinish - lngStart)
End Sub
Private Sub CommandButton1_Click()
' Place this code in any Sub or Function
Dim lngStart As Long
Dim lngFinish As Long
Dim lngCounter As Long
'TEST1
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounter = 1 To 30000
Range("A" & lngCounter).Value = lngCounter
Next
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
Debug.Print "Test1: " & CStr(lngFinish - lngStart)
'TEST2
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounter = 1 To 30000
Cells(lngCounter, 1).Value = lngCounter
Next
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
Debug.Print "Test2: " & CStr(lngFinish - lngStart)
End Sub
Option Explicit
Private Declare Function QueryPerformanceCounter Lib "Kernel32" (X As Currency) As Boolean
Private Declare Function QueryPerformanceFrequency Lib "Kernel32" (X As Currency) As Boolean
Private Sub CommandButton1_Click()
Dim frequency As Currency
Dim curStart As Currency
Dim curFinish As Currency
Dim lngCounter As Long
Dim varArr As Variant
' Get the frequency counter
' Return zero if hardware doesn't support high-res performance counters
If QueryPerformanceFrequency(frequency) = 0 Then
MsgBox "This computer doesn't support QueryPerformanceCounter"
Exit Sub
End If
' start timing
QueryPerformanceCounter curStart
' Code to be timed
For lngCounter = 1 To 100000
varArr = Array("A", "B", "C")
Next
' end timing
QueryPerformanceCounter curFinish
Debug.Print (curFinish - curStart) / frequency
End Sub
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Commented:
~bp
Author
Commented: