Log in

Fri, Sep. 22nd, 2006, 05:29 pm
compare python vs lua, ruby, PHP and Haskell

I like the comparison Erik Wrenholt has made. Via a simple fractal program, you can evaluate the pure performance of different programs.

Since it's a bit outdated, I've re-execute it with last version of Python, Lua, Ruby, PHP and Haskell:
  • Haskell ghc-6.4.2: 2sec
  • PHP-5.1.6: 2.48sec*
  • Python-2.4.3: 2.65sec
  • Python-2.5: 2.78sec
  • Lua-5.1: 3.4sec**
  • Ruby-1.8.5: 10.18sec
* I'm using microtime() instead of time()
**I'm using os.clock() instead of os.time()

All those tests was done 5x on a Windows XP(Hurrgg sorry) machine with a 2-GHz Pentium M 760 and 1GB of RAM


Based on a comment about psyco, here the result of the the script simply by adding:
import psyco
at the top the script.
  • python-2.4 + psyco 1.5.1: 0.37sec!!!

Same machine, same configuration, same methodology to make the test

Fri, Sep. 22nd, 2006 04:48 pm (UTC)
(Anonymous): Python psyco

There's a semi-jit style optimizer for Python called "psyco".
Adding the following line to the start of the python version
took the runtime from 4.1s to 0.8s.

import psyco; psyco.full()

Sat, Sep. 23rd, 2006 12:45 pm (UTC)
(Anonymous): FYI

Hi. I'd like to note that this kind of "benchmark" is not apropriate for a dynamic language as python. It's just lots of integer arithmetic. You can understand such programs, if the C version of the algorithm is not bigger than the python version. And such "benchmarks", give great results with psyco, can be easilly wrapped in Pyrex or ctypes. They can also be used to demonstrate the "python is slow, Java is fast, C# is faster than C" and other absurd colncusions.

Putting python to run such a "benchmark" is like putting a ferrari to run in the desert. It is a complex theory, but python optimizes the higher level structure of your program (through, dynamic typing, generators, exceptions, etc) and yields better results for really complex programs. The 2.4 vs 2.5 is valid nontheless.

Wed, Jul. 16th, 2008 03:29 pm (UTC)

With a C program, you can learn a lot about a program's likely performance characteristics without even running it -- simply look at the compiled machine code.

Thu, Jul. 17th, 2008 04:22 am (UTC)

If you like long words, you can say C++ is a "multi-paradigm language," but simply saying "C++ is an OOPL" is inaccurate.

Sun, Sep. 24th, 2006 02:11 pm (UTC)
(Anonymous): Wow. These results are telling.

Ruby really blows, doesn't it?

Mon, Sep. 25th, 2006 09:22 am (UTC)
(Anonymous): Re: Wow. These results are telling.

I'm using ruby for bioinformatical analysis. The time it takes to run the analysis on about 200 mb worth of data is about 5 minutes.

It takes me quite a bit more time to analyse the output of the program.. so the 'slowness' of ruby is irrelevant for me. What is relevant to me is the ease of coding. I can write a new analysis tool in minutes with ruby.

Mon, Sep. 25th, 2006 05:56 pm (UTC)
e_bananan: IronPython

IronPython 1.0.60816 on .NET 2.0.50727.42

Windows XP, Xeon 3.2, 1GB RAM


Tue, Oct. 2nd, 2007 05:22 pm (UTC)
(Anonymous): Your numbers appear off

I ran the same scripts (with current PHP and Lua) and got these results:

PHP 5.2.1 - 4.80 secs
Lua 5.1.2 - 0.84 secs

Go fig. Guess this is why it's always best to do your own benchmarks ;)

Fri, Nov. 14th, 2008 06:07 am (UTC)
ext_133475: Re: Your numbers appear off

I did similar tests on my mac book pro for lua and ruby:

Lua 5.1: 0.479 sec
Lua JIT: 0.074 sec !!!

Ruby 1.8.7: 5.83 sec

Lua is definitely the fastest scripting language

Tue, Feb. 10th, 2009 12:33 am (UTC)

It's hard to consider this experiment valid when it's so far off from all the other studies I've seen. I think there are a lot of factors that are being overlooked, probably mostly because you are running Windows, and who-knows what ports of the binaries. There is also far too limited information to say what controls are used. For example, Lua has been shown time and again to run magnitudes faster than Python in almost any situation.

Tue, Feb. 10th, 2009 12:38 am (UTC)

Lua: 0.7129
LuaJIT: 0.0803
Python: 3.4452
Psyco: 0.2840

Lua vs. Python: Lua is 4.83x faster than Python
LuaJIT vs. Psyco: LuaJIT is 3.54x faster than Psyco

Wed, Nov. 3rd, 2010 03:09 am (UTC)
(Anonymous): Haskell vs. Python vs. PHP web application benchmark