DEV Community

Cover image for ColdFusion structKeyExists vs keyExists
James Moberg
James Moberg

Posted on

ColdFusion structKeyExists vs keyExists

We have a lot of logic that processes data and it extensively uses structKeyExists to determine whether or not data exists prior to performing additional logic. I've been modernizing my legacy ColdFusion code and am wondering if we should invest any time to converting structKeyExists() to keyExists(). Are there any benefits apart from readability? Any assumptions regarding which is more performant?

While I've read that looping over a function multiple times isn't the best way to compare performance, it often reveals issues... especially when one performs 2-4 times faster than the other.

Here's some quick stats comparing 2,000 built-in cfml function calls. (NOTE: It didn't matter which version of ACF2016+ or Lucee is used.)

function ns
structKeyExists 810,284
keyExists 1,477,436

Am I going about this wrong? Am I asking the right questions? Is there any expectation that the performance times would be better (or at least the same) when using keyExists()?

Source code

Discussion (0)