Skip to content

setup() granularity and subtracting related tasks #664

@tylerjereddy

Description

@tylerjereddy

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.

cc @stefanv , @mattip

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionTriaged as a question, not requiring action after answering

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions