Thanx Martin for the code. You shaved quite a bit of time off.
But the results i got is kind of interesting.
Can someone varify this?
Add a listbox and a command button, Here's what i have done...
Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim FastRun As Long
Dim SlowRun As Long
Private Sub Command1_Click()
Dim icount As Integer
List1.AddItem "FAST then SLOW"
Call CompareCountFast
Call CompareCountSlow
List1.AddItem "Fast: " & FastRun & " Slow: " & SlowRun & " = Diff: " & SlowRun - FastRun & " Factor of Diff: " & Format(SlowRun / FastRun, "0.00")
List1.AddItem ""
DoEvents
List1.AddItem "SLOW then FAST"
Call CompareCountSlow
Call CompareCountFast
List1.AddItem "Slow: " & SlowRun & " Fast: " & FastRun & " = Diff: " & SlowRun - FastRun & " Factor of Diff: " & Format(SlowRun / FastRun, "0.00")
List1.AddItem ""
DoEvents
End Sub
Private Sub CompareCountFast()
' Place this code in any Sub or Function
Dim lngStart As Long
Dim lngFinish As Long
Dim lngCounterOne As Long
Dim lngCounterTwo As Long
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounterOne = 1 To 1000000
For lngCounterTwo = 1 To 5
Next 'lngCounterTwo
Next 'lngCounterOne
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
FastRun = CStr(lngFinish - lngStart)
End Sub
Private Sub CompareCountSlow()
' Place this code in any Sub or Function
Dim lngStart As Long
Dim lngFinish As Long
Dim lngCounterOne As Long
Dim lngCounterTwo As Long
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounterOne = 1 To 5000000
For lngCounterTwo = 1 To 5
Next lngCounterTwo
Next lngCounterOne
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
SlowRun = CStr(lngFinish - lngStart)
End Sub