0% found this document useful (0 votes)
17 views

Numby vs Numba

Uploaded by

donruffcorn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Numby vs Numba

Uploaded by

donruffcorn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

@numba.

jit
def py_diffjit(x):
n = x.size
y = np.zeros(n-1)
for i in range(n-1):
y[i] = x[i+1] - x[i]
return y

def py_diffpy(x):
n = x.size
y = np.zeros(n-1)
for i in range(n-1):
y[i] = x[i+1] - x[i]
return y

#@numba.jit
def np_diff(x):
return np.diff(x)

py_diffjit(x)

tpy =timeit.timeit ( lambda:py_diffpy(x),number=1 )


tnp =timeit.timeit ( lambda:np_diff(x),number=1 )
tjit =timeit.timeit ( lambda:py_diffjit(x),number=1)

#3.57 ms ± 8.25 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
# result = timeit.timeit(lambda:random_directions(10, 1.0), number=1)
#
print("timeit py_diff ms =",tpy*1000)
print("timeit py_diff ms =",tnp*1000)
print("timeit py_diff ms =",tjit*1000)

You might also like