Skip to content

Instantly share code, notes, and snippets.

@ZGainsforth
Last active July 22, 2016 16:37
Show Gist options
  • Select an option

  • Save ZGainsforth/419762297edb070ba14c to your computer and use it in GitHub Desktop.

Select an option

Save ZGainsforth/419762297edb070ba14c to your computer and use it in GitHub Desktop.
Simple example using numba.
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