3 ms·
I just coded up a benchmark and posted the ProTip on coderwall. http://coderwall.com/p/il1tog http://coderwall.com/p/il1tog
by nodesocket 14y ago
I just coded up a benchmark and posted the ProTip on coderwall.
http://coderwall.com/p/il1tog http://coderwall.com/p/il1tog
- encoderer 14y agoYou'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()