The tests are a little ignorant to say the least. In the comments the author says it was important "to see how the same code executed in each language", but the code itself is quite poor and could easily optimized in half a dozen spots (pre-compute array lengths, pre-increment rather than post-increment, actually run bubble sort more than once).
Secondly, the sort function only runs once, and then just does nothing 99,999 times. My guess is the V8 JIT and the GO compiler realize this and optimize it out. Since PHP is interpreted it's shit out of luck.
I would be curious what the benchmarks would be taking the count() functions out of the for loops for all languages. Those are run on each loop pass, seems pointlessly heavy.
I would like to see the results of some database query tests, as a project im considering working with wants to use node.js and mongodb over php and mysql.
I ran these tests on my own and tried out what's been discussed here. The internal count() adds the most bulk. (Note: "real sorting" just means the array is redeclared for every nth sort).
Original
Array ( [0]...) 28.913233995438
Original - with real sorting
Array ( [0]...) 29.863515853882
HN Way - with external count()
Array ( [0]... ) 4.3388159275055
HN Way - with external count() and real sorting
Array ( [0]...) 5.5680060386658
5 comments
[ 5.0 ms ] story [ 26.9 ms ] threadSecondly, the sort function only runs once, and then just does nothing 99,999 times. My guess is the V8 JIT and the GO compiler realize this and optimize it out. Since PHP is interpreted it's shit out of luck.
I've been looking into Node.js lately and have wanted to see direct comparisons between the two - I currently use PHP mainly.
Original Array ( [0]...) 28.913233995438
Original - with real sorting Array ( [0]...) 29.863515853882
HN Way - with external count() Array ( [0]... ) 4.3388159275055
HN Way - with external count() and real sorting Array ( [0]...) 5.5680060386658