4 ms·
One word: Cython. Having a fast way to interface C code, and speed up your bottlenecks is a godsend for anything that isn't a strict web app. I'm sure Ruby ha
by true_religion 15y ago
One word: Cython.
Having a fast way to interface C code, and speed up your bottlenecks is a godsend for anything that isn't a strict web app.
I'm sure Ruby has an FFI, and most likely even has a SWIG interface but Cython is far beyond that--its a typed version of Python that compiles directly down to C/C++, so you can port code between Python and Cython instanteously.
Doing just that usually makes it 2x faster.
Annotate it with types to make it more than 10x faster.
Change the algo to something you can only do efficiently in C, and it's 100-1000x faster. Seeing something go from taking 10 minutes to taking 600ms in less than a days work is fantastic.
----
Also personally, I find I like white-space scoping. Python is like psuedocodethat actually runs.
- rmk 15y agoHmm... Could you recommend some resources for this? I need to wrap a couple libraries and make them accessible in both Python and Ruby.
- synparb 15y agoThe best thing to do is to take a look at the Cython docs (http://cython.org/ http://cython.org/) and check out some of the whitepapers they have posted. There is also a bunch of cython code on github. If you search "cdef extern" you should find examples where other people have wrapped external c libraries.
- rmk 15y agoThanks!