Monday, December 25

Geek

Irony

IronPython is a version of Python written in C# for the .Net platform. It's intended as an embedded scripting language for .Net applications, but can also be used to quickly assemble applications from components written in other .Net languages. Since I'm currently working in both Python and .Net, this is of interest to me, so I downloaded IronPython* and ran my little benchmark.

And then I went and had dinner, and read a book, and read some blogs, and had some ice cream, and then came and posted this. Because IronPython has a leetle performance problem relative to CPython**; or rather, it lacks at least one very important optimisation from CPython. See if you can spot what it is:

SystemCPUClockPythonLoopStringScanTotal
AmeliaCore Duo1.66GHz2.5 (Win)1.2433.1581.0335.434
AmeliaCore Duo1.66GHz2.5 (Win)+Psyco0.0370.4831.1901.710
AmeliaCore Duo1.66GHzIronPython 1.010.6982236.3192.0452239.062

Source code for the benchmark can be found in my earlier post.

* Again; I had it on my old notebook, but that got reformatted and reinstalled at least four times, and in any case I no longer have it.

** The standard version of Python, which is written in C.


The answer: My benchmark does a lot of string concatenation, because Minx does too. But Minx and my benchmark both perform just fine because CPython has a very useful optimisation for its string concatenation.

A naive approach (typical of early Microsoft Basics, for example) would create a new string each time: new_string = old_string + whatever. In my benchmark, though, that would cause an aggregate of about a terabyte of memory traffic. You can see that CPython doesn't use a naive approach, because my notebook doesn't have 300GB/second of memory bandwidth, let alone the 2TB/second indicated by the Psyco results. CPython leaves room at the end of objects for them to grow; it updates the data in place and only copies the object when it runs out of room.

Simple things like that can make a big difference. Like a factor of 5000, in this case.

Posted by: Pixy Misa at 11:57 AM | Comments (1) | Add Comment | Trackbacks (Suck)
Post contains 325 words, total size 2 kb.

1 Seriously stuffed.

Posted by: Andrew at Tuesday, December 26 2006 06:56 PM (81C4m)

Hide Comments | Add Comment

Comments are disabled. Post is locked.
46kb generated in CPU 0.041, elapsed 0.234 seconds.
56 queries taking 0.2175 seconds, 337 records returned.
Powered by Minx 1.1.6c-pink.