Numba
#
Find similar titles
- 최초 작성자
- 최근 업데이트
Structured data
- Category
- Programming
- Big Data
Numba gives you the power to speed up your applications with high performance functions written directly in Python. With a few annotations, array-oriented and math-heavy Python code can be just-in-time compiled to native machine instructions, similar in performance to C, C++ and Fortran, without having to switch languages or Python interpreters.
Numba works by generating optimized machine code using the LLVM compiler infrastructure at import time, runtime, or statically (using the included pycc tool). Numba supports compilation of Python to run on either CPU or GPU hardware, and is designed to integrate with the Python scientific software stack.
Table of Contents
Install #
$ virtualenv --python=python3.4 --always-copy numba-env
$ source numba-env/bin/activate
$ pip install numba
Example #
#!/usr/bin/env python3
from numba import jit
from numpy import arange
import cProfile
##@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
a = arange(3000*3000).reshape(3000, 3000)
cProfile.run('sum2d(a)')
Conclusion #
Without @jit #
$ ./run.py
4 function calls in 2.482 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 2.482 2.482 <string>:1(<module>)
1 2.482 2.482 2.482 2.482 run.py:8(sum2d)
1 0.000 0.000 2.482 2.482 {built-in method exec}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
With @jit #
$ ./run.py
76244 function calls (69807 primitive calls) in 0.105 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:2264(_handle_fromlist)
1 0.017 0.017 0.105 0.105 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 <string>:12(__new__)
1 0.000 0.000 0.000 0.000 __init__.py:41(__init__)
2 0.000 0.000 0.000 0.000 __init__.py:47(create_string_buffer)
4 0.000 0.000 0.000 0.000 __init__.py:487(cast)
......
Documentation #
References #
- http://jakevdp.github.io/blog/2013/06/15/numba-vs-cython-take-2/
- http://continuum.io/blog/numba_growcut
- http://continuum.io/blog/numba_performance
- http://numba.pydata.org/
- http://nbviewer.ipython.org/urls/raw.github.com/aterrel/HPCPythonSC2012/master/02_Speeding_Python.ipynb
Suggested Pages #
- 0.025 Jython
- 0.025 Java
- 0.025 CPython
- 0.025 자바
- 0.025 Object-oriented
- 0.025 C#
- 0.025 Pyston
- 0.025 컴파일
- 0.025 객체 지향
- 0.025 IronPython
- More suggestions...