logo

... numba: compile



Notes

Not everything is faster now. 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

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.