I am a programmer for a small web development company, using classic ASP
(on IIS 6). The question has arisen as to whether a test of the form
'Len(x)=0' executes faster than 'x=""'.
My initial guess was that 'x=""' would be faster than 'Len(x)=0', but a
colleague disagrees.
I very quickly knocked up the following test script, which is followed
by the results I obtained from three runs.
===
s1 = ""
s2 = "hello"
t1 = now()
for i = 1 to 10000000
if s1 = "" then j = 1
if s2 = "" then j = 2
next
t2 = now()
for i = 1 to 10000000
if Len(s1) = 0 then j = 1
if Len(s2) = 0 then j = 2
next
t3 = now()
wscript.echo (t2-t1)*84600, (t3-t2)*84600
===
C:\Documents and Settings\Nick.BRAM-2\Desktop>test1.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
12.7291671800776 21.5416661623749
C:\Documents and Settings\Nick.BRAM-2\Desktop>test1.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
11.749999668973 21.5416667779209
C:\Documents and Settings\Nick.BRAM-2\Desktop>test1.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
11.750000284519 21.5416667779209
C:\Documents and Settings\Nick.BRAM-2\Desktop>
===
This suggests that 'Len(x)=0' is actually quite a bit slower than
'x=""'. Am I wrong? Have I missed something vital? Is this an issue for
which there has been any discussion on the Internet (and if so, where)?
If so, is there a general consensus one way or the other?
Answers to any of these questions would be greatly appreciated!
PS: I have spotted one mistake -- that I should have used 86400 instead
of 84600 -- but unfortunately it's irrelevant.
--
Nick Roberts