Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KaiyangZhou/9615dda288ff31b21d899f683d279043 to your computer and use it in GitHub Desktop.
Save KaiyangZhou/9615dda288ff31b21d899f683d279043 to your computer and use it in GitHub Desktop.
Install and using numba on mac

Install and using numba on mac

  • Mac version: 10.11.3
  • Python version: 3.5.1

Install

$ 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"

Performance

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

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment