My conclusion: count() is horribly slow. Always precalculate it, if possible.
https://github.com/php/php-src/blob/master/ext/standard/arra...In PHP they actually check the length of an array at every invocation of count(). As far as I can see the numeric value for length isn't stored anywhere.