Monday, December 25
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:
|Amelia||Core Duo||1.66GHz||2.5 (Win)||1.243||3.158||1.033||5.434|
|Amelia||Core Duo||1.66GHz||2.5 (Win)+Psyco||0.037||0.483||1.190||1.710|
|Amelia||Core Duo||1.66GHz||IronPython 1.01||0.698||2236.319||2.045||2239.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 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.
56 queries taking 0.3539 seconds, 334 records returned.
Powered by Minx 1.1.6c-pink.