Is there any way to use the timeit function to output both the function result and the time it took to process at the same time?
Right now I am using
timer = Timer('func()', 'from __main__ import func')
print timer.timeit(1)
But this just outputs the time and not the program output, which returns something at its end. I want it to output
FuncOutputGoesHere 13.2897528935
on the same line.
Ideally, I'd like to be able to take an average of the program by running it N times and then outputting the program result and its average time (a total of one output overall)
timeit
usestime.time()
, unless you are on windows, where it'll usetime.clock
(more accurate). – Dagobatimeit
uses. It'll be just as accurate. – Dagobatimer.timeit(N)/N
, yes. – Dagoba