isDefined; structure with a numeric key

Different languages have implemented an “elvis” operator to work differently even though they may have the same name. So there is no global definition of what an “elvis” operator is. For example, Kotlin has an “elvis” operator, but it also works like Lucee CFML.

1 Like

I ran your timer script a couple dozen times on my laptop and it’s only 2-3 ms for each and isDefined() is actually the winner close to half of the results. Are there real world use cases verifying that a scoped isDefined() is significantly less efficient than StructKeyExists()?

Now, when the scope is removed e.g. isDefined("customer"), then that timer jumps to as high as 30ms.

But as long as it’s scoped, isn’t it practically just as good and definitely easier to read?

I think I just found the answer to my own question from a ColdFusion Muse article by Mark Kruger way back in 2009:

“isDefined() takes no notice of your dotted notation unless the first part of the string matches the scope it is examining at the time.”

So, I realize now that the insignificant performance difference on my laptop is probably because the timer script doesn’t have as much to traverse in all the scopes as there would be in most production servers.

2 Likes

good insight, thanks for sharing… always have to be careful with micro benchmarks

1 Like