The timeit library in python takes the average time of completion. how can I make it so that is doesn't do that and only gives me the time it required to run that time. I don't need an average, I need the specific time of the last run.
Asked
Active
Viewed 47 times
0
-
1The `timeit` library averages precisely because a single run time is an unreliable measure. If you want to do something less reliable than `timeit` the solution is simple. Don't use that library. Just use `time` for your own less reliable timing. – John Coleman Jul 13 '21 at 12:02
-
how do I do it using the time library? – Vardhan Mahajan Jul 13 '21 at 12:02
-
You can also use the optional `number` parameter in the timeit function. An average of just one run is what you want. – John Coleman Jul 13 '21 at 12:04
-
By the way -- `timeit` doesn't actually return the *average* -- it returns the `total`, which would need to be divided by `number` to get an average. – John Coleman Jul 13 '21 at 12:12
-
@JohnColeman I didn't know that, so bascially if I run it 100000 times, it just tells me the amount of time it took for that, not the average time it will take over 100000 runs. – Vardhan Mahajan Jul 13 '21 at 12:15
-
If you're considering this, beware the many pitfalls of not doing sufficient "warm-up" runs to get a realistic picture of a normal call during normal operation. Unless you specifically *want* to measure the cost of the *first* call to something, including page faults and cache misses, and maybe with the CPU still at idle frequency. See [Idiomatic way of performance evaluation?](https://stackoverflow.com/q/60291987) – Peter Cordes Jul 13 '21 at 20:26
-
@PeterCordes thanks for the input I will keep this in mind – Vardhan Mahajan Jul 15 '21 at 07:02