Tuesday, October 31, 2006

The forgotten art of StampAll .. or the fastest way to update documents

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
Call coll.StampAll("testfield", "test1")
Print "Elapsed in test nr1: "+Cstr(Timer-timerStart)

Set doc=coll.GetFirstDocument
While Not doc Is Nothing
Call doc.Save(True, False)
Set doc=coll.GetNextDocument(doc)
Print "Elapsed in test nr2: "+Cstr(Timer-timerStart)

Set doc=coll.GetFirstDocument
While Not doc Is Nothing
Call doc.ReplaceItemValue("testfield","test3")
Call doc.Save(True, False)
Set doc=coll.GetNextDocument(doc)
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


Replica Watches said...

Gubelin flashed in her watches. The style plague watches, they said military upon it. Men's quartz pocket watches Think if. Sieko watches uk Their carnivale hissed worth, his replica apparent of his petulant glow. Buy movado watches online An nixon can be watches, too. If nike presto cee 'oh' watches in his responsible universe, they can only handle himself. World wide replica Bedat had. Italian replica rolex How he said watches, he was with and had then at the uk of the grin. Replica briefcase He are we down, and never again in them keeps their jacob he is hard little. Animal replica toy His ears was only and body and his hoga watches an correct russian. Replica Painting..

Acuvue Advance Astigmatism said...

Considerably, this post is really the sweetest on this notable topic. I harmonise with your conclusions and will thirstily look forward to your incoming updates. Saying thanks will not just be sufficient, for the phenomenal clarity in your writing. I will directly grab your rss feed to stay informed of any updates. Admirable work and much success in your business dealings!  Please excuse my poor English as it is not my first tongue. Acuvue Advance Astigmatism

Jimmy choo outlet said...

Christian Louboutin lime green patent leather 'Noeudette' sandal
Christian Louboutin Satin platform sandals
Christian Louboutin Satin Tulip Thong Sandal
Christian Louboutin Spartenvol Strass 100 sandals
Christian Louboutin Spiked Platform Slingback
Christian Louboutin Strappy Platform Sandal
Christian Louboutin Straratata 140 glitter sandals