r/Python•
caleb

Ideas for demonstrations and examples for Cython

I'm in the middle of preparing a Cython screencast. During scripting I've had to dream up examples that showcase Cython's ability to speed up Python code. I try to use examples that are not science- or engineering-based, simply because in these areas Cython is already well-known, and I'd like to increase the awareness of Cython beyond the scientific domain. Do you have any ideas for fun, less-scientific, but fairly short examples?

Posted Jan 8, 2016, 11:08 AM UTC

104
elbiot•

Not short, but this is game-y

https://github.com/tito/cymunk

1
calebOP•

This is great, thanks!

1
inclemnet•

Kivy's internals are largely cythonised in order to improve the performance of the event system etc (as well as for interaction with opengl, SDL2). Taking this all together is not small or simple, but maybe it can be a good reference or inspire a simpler example.

1
poorestrichman•

A great example of speedups in Cython are any tight loops. Iterating over a CSV file (a list of dicts). I used Cython once in companion with OpenCV for image analysis. I extracted a block of pixels then performed some calculations on the contents of the pixels. This was comparatively really slow in pure Python before hand because of how many pixels are in an image.

1