I get the asynchronous advantage that comes with NodeJS (and PHP with Swoole), but why is NodeJS so monstrously faster than PHP in a purely single-core, single process, synchronous use case?
Here's my PHP code:
<?php
$j = 0;
$start_time = time();
for($i = 0; $i <= 1000000000; $i++){
$j += $i;
}
$total_time = time() - $start_time;
echo $j."\n";
echo "Total Time: ".$total_time."\n";
?>
which executes in 41 seconds
And here's my NodeJS code:
console.time("elapsed");
var i;
var j = 0;
for(i = 0; i <= 1000000000; i++){
j += i;
}
console.log(j);
console.timeEnd("elapsed");
that executes in 2.9 seconds