Last active
July 22, 2016 16:37
-
-
Save ZGainsforth/419762297edb070ba14c to your computer and use it in GitHub Desktop.
Simple example using numba.
This file contains hidden or 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
| from numba import jit | |
| import numpy as np | |
| from timeit import timeit | |
| x = np.random.rand(100000) | |
| @jit | |
| def myfunc(x): | |
| for i in range(len(x)-1): | |
| x[i] **= x[i+1] | |
| myfunc(x) | |
| n = 10 | |
| print timeit(stmt='myfunc(x)', setup='from __main__ import myfunc, x', number=n)/n | |
| def myfunc2(x): | |
| for i in range(len(x)-1): | |
| x[i] **= x[i+1] | |
| try: | |
| myfunc2_fast = jit()(myfunc2) | |
| except: | |
| myfunc2_fast = myfunct2 | |
| print timeit(stmt='myfunc2(x)', setup='from __main__ import myfunc2, x', number=n)/n | |
| print 'Done' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment