Microsoft Office Tutorials and References
In Depth Information
USE TIMER TO MICRO-TIME EVENTS
The following code compares MIN(MAX to MEDIAN on 60,000 cells:
Sub TestMinMaxVsMedian()
Application.ScreenUpdating = False
Range("A1:B65000").Formula = "=Randbetween(-1000,1000)"
Range("A1:B65000").Value = Range("A1:B50000").Value
StartTime = Timer
Range("C1:C65000").FormulaR1C1 = "=MAX(0,MIN(RC1,RC2))"
Application.Calculate
Range("C1:C65000").Value = Range("C1:C65000").Value
ElapsedTime1 = Timer - StartTime
StartTime = Timer
Range("C1:C65000").FormulaR1C1 = "=MEDIAN(0,RC1,RC2)"
Application.Calculate
Range("C1:C65000").Value = Range("C1:C65000").Value
ElapsedTime2 = Timer - StartTime
Application.ScreenUpdating = True
MsgBox "MAX(MIN takes: " & ElapsedTime1 & vbCr & "MEDIAN
takes: " & ElapsedTime2
End Sub
By comparing the Timer values before and after critical sections of code, you can
compare the times required for various approaches. As shown in Figure 130,
using the functions MIN and MAX is faster than using the MEDIAN function.
Figure 130. MEDIAN is just a bit
slower than MAX and MIN .
 
Search JabSto ::




Custom Search