SnTT: Performance considerations for Instr

by Bernd Hort,
assono GmbH, Standort Hamburg,


Show-n-Tell Thursday I had to learn the hard way that are big differences in using the LotusScript function Instr case-sensitiv or case-insensitiv. With big differences I mean something like 900 times slower using the option "case-insensitive, pitch-insensitive".


If the text to search is small you won't hardly recognize any difference at all. But if the text is getting bigger you might feel the difference. For the example where I measured a 900 time slower execution time I used a quite long "Lorem ipsum" text (5539 chars) which I concatenated ten times. For the measurement I used a profiling routine from Thomas Bahn.

For i = 1 To 10
       text = text & CRLF & text
Next

For i = 1 To 1000
       Call StartProfiling("InstrTest", "case-sensitiv")
       pos = Instr(text, "Defacto")
       Call StopProfiling("InstrTest", "case-sensitiv")                
Next

For i = 1 To 1000
       Call StartProfiling("InstrTest", "case-insensitiv")
       pos = Instr(1, text, "Defacto",5)
       Call StopProfiling("InstrTest", "case-insensitiv")                        
Next

Call LogProfiles()

The results are quite astonishing.

Option Calls Execution time
total
Execution time
average
case-insensitiv 1000 459,640 0,45964
case-sensitiv 1000 0,063 0,00006

In my application I needed the case-insensitiv
method to ensure that I found all entries. It is a quite common approach
to gain performance by using more memory. I used a second variable in which
the text was stored converted to lower case. To find the position I just
used the second variable.


For
i = 1 To 1000

       Call
StartProfiling("InstrTest", "case-sensitiv mit Lcase")

       textSmallLetters = Lcase(text)

       pos =
Instr(textSmallLetters, Lcase("Defacto"))

       Call
StopProfiling("InstrTest", "case-sensitiv mit Lcase")        
               
Next


The performance gain with this approach
was quite good. It is not as fast as using the case-sensitiv option. But
for my application it was good enough.

Technical article Development

Sie haben Fragen zu diesem Artikel? Kontaktieren Sie uns gerne: blog@assono.de

Do you want an individual solution? Contact us

More interesting entries

Any questions? Contact us.

If you want to know more about our offers, you can contact us at any time. There are several ways to contact us for a non-binding first consultation.

We don’t sell your data. 100% guaranteed. See: Privacy Policy
assono GmbH

Location Kiel (headquarters)
assono GmbH
Lise-Meitner-Straße 1–7
24223 Schwentinental

Location Hamburg
assono GmbH
Bornkampsweg 58
22761 Hamburg

Phone numbers:
Human resources department: +49 4307 900 407
Marketing department: +49 4307 900 402

E-Mail adresses:
contact@assono.de
bewerbung@assono.de