3 ms·
You're re-calculating the count() on each iteration. Of course it's slower. Fix that: for($i = 0; $count = count($elements); $i < $count; $i++) { }
by encoderer 14y ago
You're re-calculating the count() on each iteration. Of course it's slower.
Fix that:
for($i = 0; $count = count($elements); $i < $count; $i++) { }
- nodesocket 14y agoYeah I know, done purposefully to see how MUCH slower this is. This is how the majority of code is written in the wild, rarely do you see the `count()` pulled outside of the `for()`.
- firlefans 14y agoThis is simply unfair, should the language maintainers be held accountable for user behaviour? A more interesting and fairer topic is whether PHPs count() is considerably slower than python's len()