Differences between revisions 1 and 2
Revision 1 as of 2024-02-17 16:34:28
Size: 594
Comment: Initial commit
Revision 2 as of 2024-02-17 16:36:20
Size: 703
Comment: Longer code
Deletions are marked like this. Additions are marked like this.
Line 34: Line 34:
Multiple quoted statements can be provided to benchmark a multi-line code snippet instead of a one-liner.

Python TimeIt

timeit is an executable script for benchmarking Python one-liners.


Installation

timeit is included in all Python installations.


Usage

Try:

$ python -m timeit "'-'.join(str(n) for n in range(100))"
10000 loops, best of 5: 30.2 usec per loop

$ python -m timeit "'-'.join([str(n) for n in range(100)])"
10000 loops, best of 5: 27.5 usec per loop

$ python -m timeit "'-'.join(map(str, range(100)))"
10000 loops, best of 5: 23.2 usec per loop

Multiple quoted statements can be provided to benchmark a multi-line code snippet instead of a one-liner.


CategoryRicottone

Python/TimeIt (last edited 2024-02-17 16:38:47 by DominicRicottone)