Recently I have needed to run a cron job every minute on a high load web server. As am currently most fluent in PHP I naturally wrote my script in PHP. However, as it’s running every minute, I do want it to be as fast as possible. Seeing as the script was very simple, I thought that the most time required to run is in loading the PHP interpreter. Maybe i could use a compiled language instead? What about Google’s new language Go?
NOTE: This was not an overall speed test. I am just trying to find out which approach would be fastest for running a cron job every minute. None of the programs tested run through a web server.
Anyway, for my test I wrote a “hello, world” command line app in each language and ran the program 1000 times. Without any further ado, here are the results, from fastest to slowest:
C: 5.37 seconds
Go: 6.23 seconds
Perl: 7.97 seconds
Python: 20.64 seconds
PHP: 41.31 seconds
There you go! PHP is a bit slow for this kind of thing! But I’m not going to write all my scripts in Go or C now (what a hassle!). So, for me…. perl wins!
Ahh, good old perl, my faithful friend! I will never forget you!