Skip to content

Accelerate Python Functions with Numba

Numba translates Python functions to optimized machine code at runtime using the industry-standard LLVM compiler library. Numba-compiled numerical algorithms in Python can approach the speeds of C or FORTRAN.

You don’t need to replace the Python interpreter, run a separate compilation step, or even have a C/C++ compiler installed. Just apply one of the Numba decorators to your Python function, and Numba does the rest.


from numba import jit
import numpy as np
import time

x = np.random.rand(10000000)

def sum_sq(a):
    result = 0
    N = len(a)

    for i in range(N):
        result+= a[i]
    return result
s_t = (time.time())
s_t_1 = time.time()
s_t_2 = time.time()
print(s_t_1 - s_t, s_t_2 - s_t_1)



  1. License under CC BY-NC 4.0
  2. Copyright issue feedback: dig +short txt
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Buy Me a Coffee