Tuesday 2 April 2013

... however arrayContains() works much faster than arrayFind()

This is a quick follow-up to that thing I mentioned the other day about the relative performance comparison of arrayFind() and listFind().

Looking at some code I was planning the refactoring of yesterday, I was reminded ColdFusion not only has an arrayFind() function, it also has an arrayContains() function. Why it has these two different functions (and a -noCase() version of arrayFind(), but not of arrayContains(), and also has arrayFindAll() / arrayFindAllNoCase() to boot) is anyone's guess. Something I observed back when I first started this blog.

I grabbed the code from the previous article that compared the performance of arrayFind() and listFind(), and added in a test of arrayContains() too. surprisingly (well: kinda) arrayContains() - despite being identical in intent to arrayFind(), as far as I can tell - performs substantially faster than arrayFind(). By a factor of about 4-5 (over a number of tests, of varying magnitudes).

Again, these sort of metrics are mostly inconsequential, but it's "interesting" that there are these differences. And if you were thinking of using arrayFind()... perhaps just use arrayContains() instead.

Oh. And in the arrays article I link to above, I suggest deprecating the whole lot of those contains / find / case / nocase functions in favour of one function which does the whole lot. I've raised a ticket for this (bearing in mind ColdFusion 11 is around the corner. Well around the corner and down the road some ways, anyhow... ;-)... it's 3534476. If you like the sound of that approach, pls vote it up.