Skip to content

timeit hardcodes plural "secs" #148254

Closed
Closed

Description

@StanFromIreland

Bug report

Bug description:

cpython/Lib/timeit.py

Lines 342 to 347 in 8687b9d

s = "" if number == 1 else "s"
print(
f"{number} loop{s} "
f"{theme.punctuation}-> "
f"{theme.timing}{time_taken:.{precision}g} secs{reset}"
)

This should instead account for the (unlikely) situation that time_taken == 1 sec, like we do for loops.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. added
    type-bug
    stdlib
    on Apr 8, 2026
  2. hugovk commented on Apr 8, 2026

    @hugovk
    Member

    We can always say "sec", we use singular for the other units:

    ❯ ./python.exe -m timeit --verbose "import time, random; time.sleep(random.random() * 5)"
    1 loop -> 3.01 secs
    
    raw times: 110 msec, 4.57 sec, 2.07 sec, 1.07 sec, 4.21 sec
    
    1 loop, best of 5: 110 msec per loop
    
    :0: UserWarning: The test results are likely unreliable. The worst time (4.57 sec) was more than four times slower than the best time (110 msec).
  3. added 5 commits that reference this issue on Apr 9, 2026
  4. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    easystdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions