4 ms·
I was a bit curious, so I did a short experiment: http://nbviewer.ipython.org/urls/dl.dropbox.com/s/l9naqibqytv8vjt/Numba_Fib.ipynb http://nbviewer.ipython.org
by Fede_V 11y ago
I was a bit curious, so I did a short experiment:
http://nbviewer.ipython.org/urls/dl.dropbox.com/s/l9naqibqytv8vjt/Numba_Fib.ipynb http://nbviewer.ipython.org/urls/dl.dropbox.com/s/l9naqibqyt...
Using numba, and adding a one line decorator to the function (without any changes whatsoever) we get around 2 orders of magnitude speed up.
Note - this doesn't involve any fancy re-writing, annotating, etc, you literally just add a decorator.
Writing really fast numerical code in Python is very easy. There's absolutely no reason not to use numba if you have small functions that just do number crunching. numba can even inline other numba functions - so you don't even pay the function call overhead.
- agumonkey 11y agoIt's funny, reminds me of old arguments when CL code could be made fast by adding a tiny (declare ...). Now it's python turn. That speed increase is damn impressive though.
- igouy 11y agohttp://pybenchmarks.org/ http://pybenchmarks.org/
- lqdc13 11y agoI love numba, but I am never successful at compiling it. Using the Anaconda distribution results in some issues as that distribution is not compatible with some other libraries and requires installing everything through conda. Most packages use Cython for this reason instead.
- ycnews 11y agoI failed to get numba installed on a Raspberry Pi 2, and I'd been wanting to try Nim, which turned out to be easy to compile on the RPi running Ubuntu. nim -r -d:release c rw_fibn.nim ... Hint: operation successful (12152 lines compiled; 2.632 sec total; 8.870MB; Release Build) [SuccessX] /home/rw/git/Nim/examples/rw_fibn Result = 8944394323791464 elapsed time: 5.376946926116943 My first try at translating Python to Nim: $ cat rw_fibn.nim import times proc fibn(reps: int64, num: int): int64 = var z: int64 for r in 1..reps: var p1, p2: int64 = 1 rnum: int = num - 2 for i in 1..rnum: z = p1 + p2 p2 = p1 p1 = z return z var start: float = times.epochTime() var res = fibn(10_000_000, 78) var finish: float = times.epochTime() echo("Result = ", res) echo("elapsed time: ", finish - start)
- once-in-a-while 11y agoReally impressive, but in CClasp (which will get even faster in future), you'll have (once finished) this kind of optimizations for ALL of the functions, both built-in and your own.
- srean 11y agohttp://c2.com/cgi/wiki?SufficientlySmartCompiler http://c2.com/cgi/wiki?SufficientlySmartCompiler
- dr_zoidberg 11y agoYour code runs about 85x faster than the original Python code, that makes it just 1,20x slower than the C code they took as base, so about 3x faster than the CClasp code. With just a decorator.