ColdFusion Optimisation Tip #1 - Use StructKeyExists instead of isdefined
Use StructKeyExists instead of isdefined
Many of ye know this old nugget already so sorry if you know this already but StructKeyExists is much much much faster than isdefined.
As Simon Whaylay says:
"IsDefined() checks not just if a variable exists, but if it is also syntactically correct. This clearly has runtime implications. That is why, when dealing with structures you should avoid isDefined() in favour of structKeyExists()."
The Proof
TEST 1 IsDefined: #endTime#ms
TEST 2 StructKeyExists: #endTime#ms
The Result
IsDefined over 100000 loops: 337ms
StructKeyExists over 100000 loops: 36ms
References
- http://www.simonwhatley.co.uk/isdefined-vs-structkeyexists
- http://mkruger.cfwebtools.com/index.cfm?mode=alias&alias=isdefined%20vs%20structkeyexists
- http://corfield.org/entry/isDefined_vs_structKeyExists
Peter Coppinger aka Topper is a neurotic web monster who spends most of his chaotic life developing ColdFusion web applications when not drinking himself into a stupor and scheming his plans for world dominance.