Hacker News new | past | comments | ask | show | jobs | submit login

Consider looking into Cython, a Python-->C source translator.

http://docs.cython.org/index.html

Cython can turn Python source into a binary `.so` that you import, thus removing the overhead of the bytecode compiler/interpreter.

You can also annotate any or all of your Python variables with C types. This way, Cython will generate raw high-performaning C using Python syntax. Other Python functions can call your optimized C versions, allowing you to optimize only the hotspots.

Further, if you need to integrate with other languages, Cython can import other libraries' C functions and call them. Conversely, it can generate a header file for your Cython code, thus allowing other languages like C to call your existing Python or Cython functions.




My experience with Cython is limited to some hacking on lxml, but I found the compilation phase extremely slow. So, sure, you get performance but you get a big hit in terms of development speed.


I don't recall Cython's default optimization level, but you may be able to decrease compilation time by adding a -O0 flag for debug builds. This StackOverflow question addresses adding optimization flags to a Cython setup.py script: http://stackoverflow.com/q/16285011/1628916


Huh. I find that if you have a short cython script, you can just hack aruond in the IPython Notebook. Evaluating a 200-line cython script takes under a second for me, which is fine for my purposes.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: