I want to convert a conventional loop
into a numba.jit
function and measure time of its processes internally. I tried using time
module but it doesn't seem to be compatible with numba.
Code:
from numba import jit, jitclass
import time
@jit(nopython=True)
def harmonic_load_flow_func():
time1 = time.perf_counter()
calc = 0
for x in range(1000000):
calc += x
print('time: {}'.format(time.perf_counter() - time1))
if __name__ == '__main__':
for count in range(10):
harmonic_load_flow_func()
Output:
C:\Users\Artur\Anaconda\python.exe C:/Users/Artur/Desktop/RL_framework/help_functions/test.py
Traceback (most recent call last):
File "C:/Users/Artur/Desktop/RL_framework/help_functions/test.py", line 14, in <module>
harmonic_load_flow_func()
File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\utils.py", line 80, in reraise
raise value.with_traceback(tb)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'perf_counter' of type Module(<module 'time' (built-in)>)
File "test.py", line 6:
def harmonic_load_flow_func():
time1 = time.perf_counter()
^
[1] During: typing of get attribute at C:/Users/Artur/Desktop/RL_framework/help_functions/test.py (6)
File "test.py", line 6:
def harmonic_load_flow_func():
time1 = time.perf_counter()
^
Process finished with exit code 1