February 24, 2008

PHP vs Ruby speed test

I recently found a post on this one particular blog that was doing benchmark for PHP vs Ruby.  The author of the blog wrote merge sort in PHP, Ruby, Perl, Python and C++, then proceeded to test the speed at which they ran.  I found it interesting that this particular merge script written in Ruby took only 3/4 of the a time to run.  So I downloaded his exact scripts that he used and tested on one of my server machines.  The only one I didn't run was the C++ version of this merge sort.

I suppose I could do a graph like Izumi over at that blog, but I don't have Office installed on this computer to make a quick graph.  If you visit that post, near the bottom will be the sources for all of the scripts that I used.  I suppose I could have written my own, but I thought it would be much quicker if I used the same scripts that he used just to be consistent.  To time these scripts, I used the linux command time and here are the direct results:

PHP
real    0m7.329s
user    0m7.299s
sys     0m0.008s

real    0m7.299s
user    0m7.290s
sys     0m0.004s

real    0m7.274s
user    0m7.269s
sys     0m0.006s

 

Ruby
real    0m7.683s
user    0m7.682s
sys     0m0.001s

real    0m7.497s
user    0m7.472s
sys     0m0.021s

real    0m7.485s
user    0m7.442s
sys     0m0.019s

 

Perl
real    0m4.595s
user    0m4.578s
sys     0m0.003s

real    0m4.627s
user    0m4.608s
sys     0m0.003s

real    0m4.634s
user    0m4.623s
sys     0m0.004s

 

Python
real    0m3.573s
user    0m3.566s
sys     0m0.002s

real    0m3.539s
user    0m3.537s
sys     0m0.002s

real    0m3.602s
user    0m3.598s
sys     0m0.005s

 

On my system, which has 4GB of ram, quad core processor, it's showing that the PHP script runs slightly faster than the Ruby script.  This is a big difference from the results of that on izumi's blog, I wonder why.  Python and Perl results were similar in that it's faster.  Maybe PHP works better in environments with a lot of RAM?  Does anyone know why there's a big difference between my results and izumi's results?  I would love to know the reason.

Filed under Web Development by A.K.

Spread the Word!

Permalink Print Comment

Leave a Comment