Good day. Today, for the sake of sports interest, I decided to check how much faster javascript php is, because I always thought php was faster.
I made 2 identical cycles in both languages, the result surprised me.
Javascript:
var start = new Date(); var x=0; for(var i=0;i<10000000;i++){ x++; } var end = new Date(); console.log('Скорость ' + (end.getTime()-start.getTime()) + ' мс');
PHP:
$begin_time = time() - 1272000000 + floatval(microtime()); $x=0; for($i=0;$i<10000000;$i++){ $x++; } $end_time = time() - 1272000000 + floatval(microtime()) - $begin_time; echo $end_time;
Everything was done in Denver on the same machine.
Results:
In all browsers, PHP counted the cycle in 1.05 seconds. But javascript turned out to be faster (well, of course, IE let down)
Firefox: JS = 33 ms
Chrome: JS = 149 ms
Opera: JS = 37ms
IE: JS = 606ms)))
Safari: JS = 137ms
In JS firefox, php was 33 times faster. Is this normal? I was just surprised by this situation :)