Skip to content

Instantly share code, notes, and snippets.

@iwiwi
Created April 29, 2017 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwiwi/9228787711a353e115ffcdee21f1a882 to your computer and use it in GitHub Desktop.
Save iwiwi/9228787711a353e115ffcdee21f1a882 to your computer and use it in GitHub Desktop.
"""
(anaconda3-4.2.0) ~/tmp% python numba_example.py [18:00:09]
Python: 3.641503095626831
Numba: 0.09061694145202637
"""
import time
from numba import jit, int32
def fib(n):
if n <= 1:
return n
else:
return fib(n - 1) + fib(n - 2)
@jit(int32(int32), nopython=True)
def fib_numba(n):
if n <= 1:
return n
else:
return fib_numba(n - 1) + fib_numba(n - 2)
def measure(f):
t = time.time()
f()
return time.time() - t
N = 35
print('Python:', measure(lambda: fib(N)))
print('Numba: ', measure(lambda: fib_numba(N)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment