-
Notifications
You must be signed in to change notification settings - Fork 191
Description
One tricky thing to deal with is state-dependent benchmarks--sorting a list or handling a StringIO
object as I mentioned for NumPy and pandas benchmarks.
The problem is that setup()
runs between repeats, but not between iterations within repeats, so if you point to an object like a list you want to sort or a StringIO object you want to read in, the work on that object will already be done in subsequent iterations and the timings will do less or close to nothing depending on the task being timed in time_operation
.
I don't think there's any obvious way around this (since that's how timeit
works -- single setup then a bunch of iterations with no setups in between). However, one possibility might be exposing convenient functionality to subtract away the timing of any operations you aren't interested in as implied by Raymond Hettinger in a comment about sort benchmarking.