Big fat warning: You only should install the below described packages,, if you know how to do it! It might break your phone. A backup might be very wise! Also your rootfs will get full, if you install to many development packages! I did it so see if it is possible. But to really work with it, I strongly suggest to install it in scratchbox! On http://wiki.maemo.org/ShedSkin I described how to install and use it in scratchbox.
Shed Skin is a tool to create python modules writen in c. This is usually used to speed up programm code which is time critial and where python is too slow. The authors of Shedskin say the following about it:
Shed Skin is an experimental compiler, that can translate pure, but implicitly statically typed Python programs into optimized C++. It can generate stand-alone programs or extension modules that can be imported and used in larger Python programs.
As I write some python software for my Maemo based phone N900, I started to look into speeding up some of the programm code.
I now got shedskin working on the phone. First of all you will have to install the gnu c compiler gcc on it. This website shows how to do it. Basically you will have to add this repository on your Maemo device:
deb http://repository.maemo.org/ fremantle/sdk free
Afterwards I had to install the needed packages with:
apt-get install build-essential
This should give you all needed packages to compile a c program.
I then downloaded the source code of Shedskin 0.6 from its project website and installed it on the phone (extract it and run “python setup.py install“). The source package has a readme file which shows you how to do it and how to create the example programs. To get them working, I also had to install the the following packages:
libgc-dev libpcre3-dev python-all-dev
When I tried to compile the examples, g++ did not understand the flag “-msse2”. I had to remove it in the Makefile . If you want to remove it permanently, you can do it in the file shedskin/FLAGS in the Shedskin source package before you install it.
I made a simple speed test, to see how much faster it would be. The test might not be well chosen, but is close to what I need.
#Speed test with shedskin 0.6 from module1 import func1 a=0 for i in range(0, 1000000): a=i+i*5 #a=func1(a) print a
#Module for speed test with shedskin 0.6 def func1(a): for i in range(0, 1000000): a=i+i*5 return a if __name__ == '__main__': print func1(0)
To test it with the module, I commented out the for loop in test.py and enabled the function call func1. To measure the time I used “time python test.py”. The measurements gave the following (average results):
real 0m5.560s user 0m4.797s sys 0m0.172s
with c module:
real 0m0.294s user 0m0.250s sys 0m0.039s
We can see that the program is approx 18 times faster with the c module!
This for sure shows how useful it can be to use c for certain functions.
The disadvantage how ever is the size of the created module, it is 1.3 MB.