Error 

Archive for August 5th, 2006

Python vs. PHP

Posted August 5, 2006 at 05:08pm in Computers, Programming

I have been programming for about 7 years now off and on and I feel I have let myself down by not really following through on one single language. So I said to myself that Python will be the language I will concentrate on learning inside and out.

This morning I created two script, one in Python and another in PHP. Each script loops through a FOR statement 2,000,000 times calculating the MD5 hash of N + N, N equaling the number of passes thus far. It is a very basic script showing a quick speed comparison between the languages.

Here are the two scripts: PHP, Python

and the results

Round 1 - 2,000,000 Passes
PHP = 21.4227 sec
Python = 9.8737 sec

Round 2 - 2,000,000 Passes
PHP = 21.1122 sec
Python = 9.7241 sec

Round 3 - 1,000,000 Passes
PHP = 9.811 sec
Python = 4.429 sec

Round 4 - 1,000,000 Passes
PHP = 9.857 sec
Python = 4.280 sec

As you can see, Python is more than 2 times faster than PHP in performaing this operation. I really enjoy writing PHP, but I think for any web applications I write that need to interface with a standalone desktop application or anything that needs real power I will choose Python.