Skip to content

Documentation of timeit.Timer.timeit should mention that the return value depends on the timer #105052

Closed
@tfpf

Description

@tfpf

Documentation

At the moment, it is as follows.

cpython/Lib/timeit.py

Lines 164 to 169 in cb4615f

def timeit(self, number=default_number):
"""Time 'number' executions of the main statement.
To be precise, this executes the setup statement once, and
then returns the time it takes to execute the main statement
a number of times, as a float measured in seconds. The

The return value may not always be a float measured in seconds. If a different timer function is used:

timeit.timeit(timer=time.perf_counter_ns)

then it is an integer measured in nanoseconds.

Not entirely sure how to document it unambiguously, but perhaps it can be reworded to say something like: '… as a number measured in the time unit returned by the timer argument of the constructor (by default: a float measured in seconds).' Or similar?

Linked PRs

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dir

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions