|
おはようございます。
>
>ある程度速度を要求されるのでしたら、
>
>> maxD = IIf(AAA(i) > maxD, AAA(i), maxD)
>> minD = IIf(AAA(i) < minD, AAA(i), minD)
>
> If AAA(i) > maxD Then maxD = AAA(i)
> If AAA(i) < minD Then minD = AAA(i)
>
>にしたほうが若干速くなります。
>
>ループ回数が多くないと、速度差は実感できませんが...
ではさっそく 検証。
'===========================================================
Sub test()
Dim AAA(1 To 1000000)
Dim i As Long
Dim maxD As Long
Dim minD As Long
Dim tm As Double
For i = 1 To UBound(AAA)
AAA(i) = CLng(Rnd() * 3000000) + 1
Next
MsgBox "ready"
tm = [now()]
maxD = AAA(1): minD = AAA(1)
For i = 2 To UBound(AAA)
maxD = IIf(AAA(i) > maxD, AAA(i), maxD)
minD = IIf(AAA(i) < minD, AAA(i), minD)
Next
Debug.Print maxD
Debug.Print minD
Debug.Print Application.Text([now()] - tm, "hh:mm:ss.00")
'**********************************************************
tm = [now()]
maxD = AAA(1): minD = AAA(1)
For i = 2 To UBound(AAA)
If AAA(i) > maxD Then maxD = AAA(i)
If AAA(i) < minD Then minD = AAA(i)
Next
Debug.Print maxD
Debug.Print minD
Debug.Print Application.Text([now()] - tm, "hh:mm:ss.00")
End Sub
私の環境で3秒ほど差がありました。
|
|