Assignment Statements, Comparisons & Observations
Font: Size: + -

PHP vs Python vs JavaScript

Friday, April 03, 2020
I was writing code to solve a particular problem on in PHP 7.4 and found that it was taking a lot of time to execute. 10 seconds. Then ported the same code in Python3 thinking it'll be much faster. Nope. 20 seconds. Then I tried JavaScript running not in the browser but in node. Quarter of a second !

Same code in three different languages - three nested loops.

$ time php contiguous-subarray.php

real    0m10.180s
user    0m10.152s
sys 0m0.018s

$ time python3

real    0m20.704s
user    0m20.676s
sys 0m0.017s

time node contiguous-subarray.js 

real    0m0.225s
user    0m0.213s
sys 0m0.010s

JavaScript wins.