Created
April 29, 2017 09:05
-
-
Save iwiwi/9228787711a353e115ffcdee21f1a882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
(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