Skip to content

gh-146609: Add colour to timeit CLI output - #146610

Merged
hugovk merged 9 commits into
python:mainfrom
hugovk:3.15-timeit-colour
Apr 8, 2026
Merged

hugovk merged 9 commits into
python:mainfrom
hugovk:3.15-timeit-colour

Conversation

@hugovk

@hugovk hugovk commented Mar 29, 2026 •

Copy link
Copy Markdown
Member

Standard and verbose:

./python.exe -m timeit "'-'.join(str(n) for n in range(100))"
./python.exe -m timeit --verbose "'-'.join(str(n) for n in range(100))"
image

With a warning:

./python.exe -m timeit "import time, random; time.sleep(random.random() * 0.9)"
image

As usual, environment variables can control colour output.


📚 Documentation preview 📚: https://cpython-previews--146610.org.readthedocs.build/

Comment thread Lib/test/test_timeit.py Resolved
Comment thread Lib/timeit.py Resolved
Comment thread Lib/timeit.py Resolved
Comment thread Lib/test/test_timeit.py Resolved
@ambv

ambv commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Nitpick: I would segment this differently. The fact that the entire line after "raw times:" is just cyan is a wasted opportunity. Would make sense to me to make the commas delimiting the values be colored the same way as the arrows.

@hugovk

hugovk commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

Like this?

image
@ambv

ambv commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Yes, that looks better to me!

@hugovk
hugovk merged commit 8687b9d into python:main Apr 8, 2026
56 checks passed
@hugovk
hugovk deleted the 3.15-timeit-colour branch April 8, 2026 13:18
@hugovk

hugovk commented Apr 8, 2026

Copy link
Copy Markdown
Member Author

Thanks both for the reviews!

@bedevere-bot

This comment was marked as off-topic.

ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
Co-authored-by: Stan Ulbrych <stan@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants