AW: Gestatte noch ein Wort, @Matthias G
01.06.2007 17:32:00
ingUR
... denn die im Raum schwebende Frage nach dem Geschwindigkeitsunterschied zwischen den Versionen soll nicht unbeantwortet bleiben (bitte Fragestellung nicht allzu ernst nehmen):
The winner is
Cells(1,1) = 1
Cells(1,1) = 1 wird schneller ausgeführt als Cells(1,1).Value = 1
Die "schnellere" Version Cells(1,1)=1 bringt bei 100.000 Läufen 2,72% Zeitersparnis gegenüber der "langsameren" Version Cells(1,1).Value=1, was wohl daran liegt, dass wenn die Eigenschaft fehlt, auf die Untersuchung, welche Eigenschaft gefragt ist, verzichtet werden kann, da Value sofort unterstellt wird.
Auf dem Gerät, auf dem ich dieses Test duchgeführt haben, werden für die Zuweisung mit der Standardschreibweise bei 100.000 Läufen 21250 msec benötigt, während bei der "längere" Version 21902 msec gestoppt werden.
Hier der Programmcode, mit dem in einer leeren Arbeitsmappe gestestet wurde:
Option Explicit
Dim starttime As Long, Wartezeit As Date
Declare Sub sleep Lib "kernel32" (ByVal dwMSecs As Long)
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Sub Testen()
Dim i As Long, nLoops As Long, n As Long, r As Long
Dim time0 As Long, time1 As Long, time2 As Long
For nLoops = 10000 To 100000 Step 10000
Application.ScreenUpdating = False
r = r + 1
n = nLoops
'Teste Zeitbedarf der Schleife
time0 = timeGetTime
For i = 1 To n
Next i
time0 = timeGetTime - time0
time1 = timeGetTime
For i = 1 To n
Cells(1, 1) = 1
Next i
time1 = timeGetTime - time1 - time0
time2 = timeGetTime
For i = 1 To n
Cells(1, 1).Value = 1
Next i
time2 = timeGetTime - time2 - time0
Cells(r + 1, 2) = n
Cells(r + 1, 3) = time1
Cells(r + 1, 4) = time2
Cells(r + 1, 5) = time1 / n
Cells(r + 1, 6) = time2 / n
Cells(1, "H") = Application.WorksheetFunction.Average(Range("E2:E" & r))
Cells(1, "I") = Application.WorksheetFunction.Average(Range("F2:F" & r))
Cells(1, "J") = 100 * Cells(1, "H") / Cells(1, "I")
Cells(2, "H") = Application.Max(Range("E2:E" & r))
Cells(2, "I") = Application.Max(Range("F2:F" & r))
Cells(3, "H") = Application.Min(Range("E2:E" & r))
Cells(3, "I") = Application.Min(Range("F2:F" & r))
If r > 2 Then
Cells(4, "H") = Application.WorksheetFunction.StDev(Range("E2:E" & r))
Cells(4, "I") = Application.WorksheetFunction.StDev(Range("F2:F" & r))
End If
Cells(1, "G") = n
Application.ScreenUpdating = True
Next nLoops
End Sub
Gruß,
Uwe