>I concur, though if you make the variable name dynamic (change '1' to
>'#i#'), then the results are as you'd expect (isDefined being about 33%
>slower).  It seems that isDefined is doing some sort of
>caching to speed it
>up on repetitious lookups.

That speed difference could also be down to the implementation of how a
dynamically named variable is evaluated in isDefined() vs structKeyExists(),
but it could equally likely be due to caching as you suggest.

In either case, the absolute speed difference between them on my machine is
of the order of tens of nanoseconds which is hardly a compelling argument
for using one over the other.

If you take away the variables prefix in the isDefined() call and use a
dynamic variable name the difference jumps to a factor of about 300 in
favour of using structKeyExists(), but that's really comparing apples to
oranges since you're telling structKeyExists() exactly where to look, but
you're not telling isDefined() anything other than that you want to know if
there is a variable somewhere whith that name.

I'd still advocate using structKeyExists() over isDefined() because it's
less likely to introduce bugs where you have something like
variables.variables.foo.

Spike
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to