Learn Before
Code

Numba Module Example

Let's compare the execution time of the following function. It adds 1 to a variable 1 billion times. With Numba:

from numba import jit import time @jit(nopython=True, cache=True, fastmath={'fast'}) def numba_test(): x = 0 for i in range(1000000000): x += 1 start = time.time() numba_test() print(time.time() - start)

This returned 0.031908512115478516 seconds.

Without Numba:

import time def test(): x = 0 for i in range(1000000000): x += 1 start = time.time() test() print(time.time() - start)

This returns 23.248998165130615 seconds. As we can see this example of using Numba is 728x times faster.

0

1

Updated 2021-02-27

Tags

Python Programming Language

Data Science