I've been analyzing an agent and found that it uses NotesDocumentCollection.StampAll(fieldname, value) method. I knew about the existence of the method but didn't remember about actually using it, so I decided to test how effective it was compared with other methods. For comparing I used looping through all documents in a document collection and updating them one by one.
The result was that for updating one field StampAll is 80% faster than any other method. To update field called "testfield" in 15000 documents using StampAll("testfield", "test") took
31 seconds, using doc.testfield="test" tool
54 seconds and doc.ReplaceItemValue("testfield", "test") took
50 seconds.
Surprisingly to update the same field using @Formula (Field testfield:="test") took 120 seconds. Using Simple Action it took 65 seconds.
One disadvantage with StampAll method is that it updates
only one field at a time. So if you want to update 2 fields in a document, it would take 2 times as long time, while with other methods the difference is about +10% for each additional field.
Here is the source code of the agent and the agent's output.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection
Dim doc As NotesDocument
Dim item As NotesItem
Set db=session.CurrentDatabase
Set coll=db.AllDocuments
timerStart=Timer
Call coll.StampAll("testfield", "test1")Print "Elapsed in test nr1: "+Cstr(Timer-timerStart)
timerStart=Timer
Set doc=coll.GetFirstDocument
While Not doc Is Nothing
doc.testfield="test2"
Call doc.Save(True, False)
Set doc=coll.GetNextDocument(doc)
Wend
Print "Elapsed in test nr2: "+Cstr(Timer-timerStart)
timerStart=Timer
Set doc=coll.GetFirstDocument
While Not doc Is Nothing
Call doc.ReplaceItemValue("testfield","test3")
Call doc.Save(True, False)
Set doc=coll.GetNextDocument(doc)
Wend
Print "Elapsed in test nr3: "+Cstr(Timer-timerStart)
End Sub
Elapsed in test nr1: 30,89014 Elapsed in test nr2: 54,27002 Elapsed in test nr3: 50,06982