March 2010


Natively-compiled Python with Shed Skin

I watched an interesting Google tech talk about Google Native Client and tried it out. Apparently it needs a tool called gclient from the Google Chromium depot_tools. I installed it (using Yaourt in Arch Linux, of course) and was suprised to see some Python files compiled by GCC.

This was done by another Google project called Shed Skin. It's a Python-to-C++ compiler that uses type analysis. I wondered how the performance impact was and wrote a small script that sorts large lists of numbers. The time measurements are shown below:


  • AMD64 3000+
  • Linux 2.6.32-ARCH x86_64
  • Python 2.6.4
  • Shed Skin 0.3-2
  • Built-in sorting algorithm


# -<em>- coding: utf-8 -</em>-
from random import randint
from time import time
data = []
for i in range(1 << 16):
 data.append(randint(0, 255))
start = time()
print time() - start


Using python it's quite obvious:

$ python


or you can just chmod +x and then enter ./

Shed Skin is really simple to use as well:

$ shedskin

[iterative type analysis..]
[generating c++ code..]

$ make

g++ -O2 -pipe -Wno-deprecated  -I. ...

$ ./sort



In the end, Shed Skin was about eight times faster than CPython, which is great, but not as great as I had expected. I wonder how PyPy compares to this.

Implementation1^16 Integers2^23 Integers
Shed Skin7ms1316ms
Execution time (lower is better)