6 ms·
My conclusion: count() is horribly slow. Always precalculate it, if possible. https://github.com/php/php-src/blob/master/ext/standard/array.c#L306 https://gith
by program 14y ago
My conclusion: count() is horribly slow. Always precalculate it, if possible.
https://github.com/php/php-src/blob/master/ext/standard/array.c#L306 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.
- fooyc 14y agoIn default, non recursive mode, it's only returning the value of zval->nNumOfElements (with a few indirections). It's not count() that's benchmarked here, its the difference between "$a < $b" and "$a < function_call($b)".