Skip to content

Simplify normalize_perf now that pytest-perf resolves sub-microsecond timings #539

Description

@jaraco

#533 added a normalize_perf exercise that repeats the operation 1000× to produce a measurable timing:

def normalize_perf():
    # python/cpython#143658
    import importlib_metadata  # end warmup

    # operation completes in < 1ms, so repeat it to get visibility
    # https://github.com/jaraco/pytest-perf/issues/12
    for _ in range(1000):
        importlib_metadata.Prepared.normalize('sample')

The loop exists only because a single Prepared.normalize('sample') call runs well under a microsecond — below the resolution pytest-perf had at the time. It parsed timeit output into a microsecond-resolution datetime.timedelta, so sub-microsecond timings rounded to zero and the control/experiment comparison was meaningless.

As of pytest-perf 0.16.0, timings are compared with nanosecond precision (via tempora.Duration), resolving jaraco/pytest-perf#18. The amplification loop is no longer needed; normalize_perf can exercise a single call:

def normalize_perf():
    import importlib_metadata  # end warmup

    importlib_metadata.Prepared.normalize('sample')

This would require pytest-perf >= 0.16 for the perf run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions