Calmcode - numba: compile

Compile

1 2 3 4 5 6

Not everything is faster now in numba. The first time you call the decorated function it will need to compile.

import time

@nb.njit
def func_test(n):
    result = 0
    for i in range(n):
        squared = n * n
        result += squared
    return result

start = time.time()
func_test(1000)
print(time.time() - start)

start = time.time()
func_test(1000)
print(time.time() - start)

There's also the risk that your function contains code that cannot be compiled by numba. Here's an example of such a function.

@nb.njit
def func_test(n):
    result = {}
    for i in range(n):
        new_dict = {'a' * n: n}
        result[squared] = new_dict
    return result