Answer the question
In order to leave comments, you need to log in
Why is code with numba slower than code without it?
There is a class, I create many of its instances, for each of which it is necessary to perform certain mathematical calculations. To make this whole thing work faster, I'm trying to use numba.
@jitclass([('ind', uint)])
class CheckTheory:
def __init__(self, ind):
self.ind = ind
def complex_math_calculations(self, inc_value):
self.ind += inc_value
@njit(parallel=True, fastmath=True)
def main_func():
classSamplesArray = []
# init class samples
for i in range(10000):
classSamplesArray.append(CheckTheory(i))
for sample in classSamplesArray:
sample.complex_math_calculations(10)
start_time = time.time()
main_func()
print(time.time() - start_time)
Answer the question
In order to leave comments, you need to log in
Try doing this instead of the last three lines:
start_time = time.time()
for x in range(1000):
main_func()
print(time.time() - start_time)
Numba: 1.2769
No numba: 6.77
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question