Domino 9 und frühere Versionen > Entwicklung
Script Problem
Performance:
laut Redbook => sg245602.pdf
Use For Loops Instead of Do Loops or While Loops
For loops are faster than Do loops and While loops because the condition that bounds the Do or While loop must be evaluated at each iteration of the loop. In the following example, the first fragment runs 60 percent faster than the
second fragment.
Fragment A
For y = 1 to 15000
z = z+1
Next
Fragment B
Do
z = z+1
y = y+1
Loop While y <= 15000
The performance savings occur because the looping overhead is minimized in the For case. If your loop does a lot of work, the actual performance improvement will be less than the 60 percent mentioned since the looping overhead becomes a smaller fraction of the total loop time.
########
Use Forall Instead of For in Referencing Array Elements
Forall loops are faster in handling arrays than For loops.
Forall is 75 percent faster than For when referencing all elements in a 1-dimensional numeric array, and 50 percent faster when referencing elements in a 2-dimensional array. Similar performance improvements occur in arrays with higher numbers of dimensions. String arrays achieve somewhat less performance improvement than numeric arrays, but these are still significant.
cu
eknori:
--- Zitat ---For i = 1 to dc.Count
--- Ende Zitat ---
würde ich auch immer dann verwenden, wenn ich mit einer col arbeite; denn da wird der Count intern bereits beim Füllen der Col ermittelt
--- Zitat ---do while doc is Nothing
--- Ende Zitat ---
ist wohl noch ein Relikt aus der Zeit, als es noch Keine ViewEntryCollection gab.
da mußte dann in der Tat die komplette View durchlaufen werden, da man ja nie wissen konnte, wie viele docs in der View sind.
Aber abei der NotesViewEntryClass gibt es ja auch die Property Count. Sollte dann auch performanter sein.
eknori
Rob Green:
gutes Zitat, Perfomance und sehr hilfreich denke ich.
Nur in dem Falle eines Loops durch Docs zählt das Beispiel oben nicht, weil der While Loop einen zusätzlichen Rechen Step beinhaltet, den das For so nicht hat. Das Ergebnis ist natürlich dann nicht mehr überraschend.
Hab selbst aufgrund des Tips von Flamme und harkpabst aus The View die StopWatch Klasse genommen und folgende Codes über 25000 Docs miteinander verglichen und kam auf folgendes Ergebis vorab, daß die While bei insgesamt á 10 Läufen idR zwischen 1.5 und 2 Sekunden schneller war. Dabei hat die FOR Schleife immer im Bereich GetNextDocument "an Boden verloren". Das spiegelt mE meine Annahme wider, daß ein Check auf True/False (mit "is Doc nothing") schneller als ein Check auf einen Schleifendurchlauf Zähler ist (For i=1 to viewcoll.count). Der Code ist bei beiden total identisch, außer dem Schleifenrumpf. Fairerweise bilde ich bei beiden den ViewCollection.Count, obwohl ich das bei While nicht bräuchte.
For Schleife ("exemplarisch" 1 aus 10)
seconds % calls secs/call event
===========================================================================
00054,691 100,0% 0000001 00054,691 Total run time
00033,586 061,4% 0025318 00000,001 Process Document
00012,577 023,0% 0025318 00000,000 GetNextDocument
00000,000 000,0% 0000001 00000,000 GetFirstDocument
WHILE Schleife ("exemplarisch" 1 aus 10)
seconds % calls secs/call event
===========================================================================
00052,323 100,0% 0000001 00052,323 Total run time
00032,758 062,6% 0025318 00000,001 Process Document
00011,944 022,8% 0025318 00000,000 GetNextDocument
00000,000 000,0% 0000001 00000,000 GetFirstDocument
Der Code für FOR und WHILE im Kopfbereich 100% identisch:
Dim stopwatch As Stopwatch
Dim session As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim count As Integer
Dim vcentries As Integer
Set stopwatch = New Stopwatch
Set session = New NotesSession
Set db = session.CurrentDatabase
Set view = db.GetView("LoopTest")
count = 0
Dim vc As NotesViewEntryCollection
Set vc = view.AllEntries
vcentries = vc.count
Call stopwatch.Start("GetFirstDocument")
Set doc = view.GetFirstDocument
Call stopwatch.Stop("GetFirstDocument")
UND hier die For Schleife (Code oben und dieser Part im Agent No.1, separat angestoßen)
For i=1 To vcentries
Call stopwatch.Start("Process Document")
count = count + 1
Print Cstr(count)
Call stopwatch.Stop("Process Document")
Call stopwatch.Start("GetNextDocument")
Set doc = view.GetNextDocument(doc)
Call stopwatch.Stop("GetNextDocument")
Next
UND hier die WHILE Schleife (Code oben und dieser Part im Agent No.2, separat angestoßen)
While (Not doc Is Nothing)
Call stopwatch.Start("Process Document")
count = count + 1
Print Cstr(count)
Call stopwatch.Stop("Process Document")
Call stopwatch.Start("GetNextDocument")
Set doc = view.GetNextDocument(doc)
Call stopwatch.Stop("GetNextDocument")
Wend
Womit bewiesen wäre, daß Notes nicht immer Notes ist, eine For Schleife nicht immer schneller als eine While und eine While nicht immer schneller als eine For und Statistiken eben Statistiken sind.
Unterzeichnet "Gruppe der hebräischen While Volksfront"
eknori:
Otternasen, köstliche Otternasen !!
Rob Green:
;D ;D 8) 8)
sollten wir nicht mal ein Treffen machen mit VideoBeilagen á la Monty?
Navigation
[0] Themen-Index
[#] Nächste Seite
[*] Vorherige Sete
Zur normalen Ansicht wechseln