I am using Jupyter notebook, and I have a code which I will measure its performance using %%timeit -o after that I need to extract the measured values (time and error) and store each one of them in a separate variable, I tried to use res = _ which will return the full string
<TimeitResult : 248 ms ± 27.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)> after that I tried to parse it using regualr expression, with the following code:
timeitResult = res
errorPattern = '±(.*)ms'
measurePattern = ':(.*)s'
error_search = re.search(errorPattern, timeitResult , re.IGNORECASE)
if error_search:
error= error_search.group(1)
measure_search = re.search(measurePattern , timeitResult , re.IGNORECASE)
if measure_search :
measure = measure_search .group(1)
print(float(error), float(measure))
but the final result will be:
(27.7, 27.7)
which is only the error, and I am not even able to fetch the value of measure alone.
Any help would be really appreciated.