- Mac version: 10.11.3
- Python version: 3.5.1
$ brew tap homebrew/versions
$ brew install llvm37
$ export LLVM_CONFIG=/usr/local/Cellar/llvm37/3.7.1/bin/llvm-config-3.7
$ pip install llvmlite
$ pip install numba
$ python -c "from numba import jit"
from datetime import datetime
from numba import jit
from numpy import arange
# jit decorator tells Numba to compile this function.
# The argument types will be inferred by Numba when function is called.
@jit
def sum2d(arr):
M, N = arr.shape
result = 0.0
for i in range(M):
for j in range(N):
result += arr[i,j]
return result
begin = datetime.now()
size = 10000
a = arange(size * size).reshape(size,size)
print(sum2d(a))
end = datetime.now()
print("duration: {} ms".format(end - begin))
Result:
- Without
@jit
: 0:00:30.376665 ms - With
@jit
: 0:00:00.630570 ms