I used numba to accelerate parts of my Python code using the autojit decorator. Tests pass and %timeit shows that the code is indeed accelerated.
The first execution is slow because, I assume, numba is compiling the code. Makes sense. But when I run a suite of tests, they run extremely slowly, from 10 tests in about 10 seconds before my changes to the same tests in 117 seconds. It seems like numba must be compiling again and again, separately for each test.
Can I avoid this? I have tried running one simple test in the setUp function, thinking that might compile the function there once for all the tests, but this did not change the run time significantly.
Something like this might work:
from numba import autojit
def autojit_except_when_unit_testing(func):
if UNIT_TESTING:
return func
return autojit(func)
Possibly also bump numba's issues regarding caching, as this is a pretty important use case. I would normally be pretty hesitant to run unit tests and production code in such different environments, but unit tests that take forever don't get run as often. You should almost certainly test with numba as well, just less often.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With