Size: 703
Comment: Longer code
|
← Revision 3 as of 2024-02-17 16:38:47 ⇥
Size: 821
Comment: See also
|
Deletions are marked like this. | Additions are marked like this. |
Line 36: | Line 36: |
---- == See also == [[https://docs.python.org/3/library/timeit.html|Python timeit module documentation]] |
Python TimeIt
timeit is an executable script for benchmarking Python one-liners.
Contents
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.
See also
Python timeit module documentation