Mika Heinonen's Blog
Counter
1021

LotusScript: over 780% faster checking for empty strings
Wednesday, 27 February 2008 19:44:34 EET

I read on planetlotus.org about Bob Balaban's test of the speed difference between s="" vs len(s)=0 checking ( http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/performance-testing-technique ).

My test agent looks like this:
Sub Initialize
   Dim n As Long, ni As Long
   n=10 ' number of test repeats
   Dim t1 As Double, t2 As Double, tn As Double, tt As Double
   Dim i As Integer, j As Integer, k As Long
   Const x=10000
   Const s="xxxxxxxxxx"
   For ni=1 To n
      t1=Timer
      For i=1 To x
         For j=1 To x
            k=Len(s)=0
         Next
      Next
      t2=Timer
      tn=t2-t1
      tt=tt+tn
      Print ni & ": " & Format(tn,"00000.00000") & "s."
   Next
   Print "Average: " & tt / n & "s."
End Sub

The line with k=Len(s)=0 varied and gave the following average timings over 10 tests:



Const s=""k=Len(s)=07.532s
Const s=""k=s<>""58.938s
Const s="xxxxxxxxxx"k=Len(s)=07.688s
Const s="xxxxxxxxxx"k=s<>""63.089s
Const s="xxxxxxxxxx"k=s=""65.770s


That means, even with small loops like 1 billion iterations, you get almost a minute faster results! Anyway, the number of iterations is not so important and you can't really judge on that, as someone might need even bigger iterations, but the fact that it's over 780% faster to use len(s) is important.

I don't think it's concidence that several people started to blog about LotusScript performance practices, just after I started to think about revising the LotusSphere 2007 LotusScript speed presentation, even before I posted anything on my blog. I think there is somekind of shared mind, which we can't explain scientifically yet.