PHP Web Development Beneficial For Online Business

PHP Web Development Beneficial For Online Business

Saturday 19 January 2013

Speed test: PHP vs Perl vs Python vs Go vs C

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!

2 comments: