Understanding timeit Output in Python 2026 with Efficient Code
The output of timeit can look confusing at first. In 2026, with faster Python interpreters and free-threading, correctly interpreting timeit results is essential for making accurate performance decisions and avoiding common benchmarking mistakes.
This March 15, 2026 guide explains exactly what every part of timeit output means and how to use it effectively for efficient code optimization.
TL;DR — Key Takeaways 2026
timeitshows the best time from multiple runs, not the average- The number after "loops" is how many times the code ran per measurement
- Lower time = better performance
- Use
repeat+minfor reliable results - Always compare relative improvement, not absolute microseconds
1. Typical timeit Output Explained
import timeit
result = timeit.timeit(
stmt="sum(range(100000))",
number=100,
repeat=5
)
print(result)
Sample Output: 0.08523456789012345
This means the code ran 100 times per measurement, repeated 5 times, and 0.08523 seconds is the best (fastest) of those runs.
2. Classic timeit Output Format
1000 loops, best of 5: 284 usec per loop
Breakdown:
1000 loops→ Code executed 1000 times in each timingbest of 5→ Ran the test 5 times and picked the fastest284 usec per loop→ Average time for one execution in the best run
3. Modern Benchmark Helper (2026)
import timeit
def benchmark(stmt, setup="", number=1000, repeat=7):
timer = timeit.Timer(stmt=stmt, setup=setup)
times = timer.repeat(repeat=repeat, number=number)
best = min(times) / number
print(f"{stmt[:60]:60} → {best*1_000_000:8.2f} µs per loop")
return best
# Usage
benchmark("sum(range(100000))")
benchmark("np.sum(np.arange(100000)**2)", setup="import numpy as np")
4. Best Practices for Interpreting timeit Output
- Focus on the best time (lowest value)
- Use the same
numberwhen comparing versions - Pay attention to microseconds (µs) for small functions
- Measure relative improvement (e.g., 3.2x faster)
- Use realistic data sizes
Conclusion — Understanding timeit Output in 2026
Mastering how to read timeit output is a fundamental skill for writing efficient Python code. In 2026, developers who correctly interpret these numbers make smarter optimization decisions and build significantly faster applications.
Next steps:
- Use the
benchmark()helper in your projects - Related articles: Why Should We Time Our Code 2026 • Efficient Python Code 2026