Conveniently measure and compare the execution times of multiple statements.
Project description
timeit_compare
Conveniently measure and compare the execution times of multiple statements.
Installation
To install the package, run the following command:
pip install timeit_compare
Usage
Here is a simple example from the timeit library documentation:
>>> from timeit_compare import cmp
>>> cmp(
... "'-'.join(str(n) for n in range(100))",
... "'-'.join([str(n) for n in range(100)])",
... "'-'.join(map(str, range(100)))"
... )
timing now...
|████████████| 21/21 completed
Table. Comparison Results (unit: s)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────
Idx Mean ↓ Median Min Max Stdev Stmt
───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 5.9e-6 75.7% █████▎ 5.9e-6 5.9e-6 6.0e-6 3.8e-8 '-'.join([str(n) for n in range(100)])
2 7.3e-6 93.4% ██████▌ 7.3e-6 7.2e-6 7.4e-6 7.6e-8 '-'.join(map(str, range(100)))
0 7.8e-6 100.% ███████ 7.8e-6 7.7e-6 8.0e-6 1.1e-7 '-'.join(str(n) for n in range(100))
───────────────────────────────────────────────────────────────────────────────────────────────────────────────
7 runs, 10290 loops each, total time 1.509s
In a command line interface, call as follows:
python -m timeit_compare - "'-'.join(str(n) for n in range(100))" - "'-'.join([str(n) for n in range(100)])" - "'-'.join(map(str, range(100)))"
help
usage: python -m timeit_compare [-h] [-v] [- STMT [STMT ...]] [-s [SETUP ...]] [-r REPEAT] [-n NUMBER] [-t TOTAL_TIME] [-w WARMUPS] [--no-progress] [--sort-by {mean,median,min,max,stdev}]
[--no-sort] [--reverse] [-p PRECISION] [--percentage [{mean,median,min,max,stdev} ...]] [-f FILE]
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-, --stmt STMT [STMT ...]
statement to be timed. A multi-line statement can be given by passing multiple strings simultaneously in an argument
-s, --setup [SETUP ...]
statement to be executed once initially for the last --stmt argument, if there are no --stmt arguments before this, it indicates the default setup statement for all --stmt
(default: 'pass'). A multi-line statement is processed in the same way as --stmt
-r, --repeat REPEAT how many times to repeat the timers (default: 7)
-n, --number NUMBER how many times to execute statement (default: estimated by -t)
-t, --total-time TOTAL_TIME
if specified and no -n greater than 0 is specified, it will be used to estimate a -n so that the total execution time (in seconds) of all statements is approximately equal
to this value (default: 1.5)
-w, --warmups WARMUPS
how many times to warm up the timers (default: 1)
--no-progress no progress bar
--sort-by {mean,median,min,max,stdev}
statistic for sorting the results (default: 'mean')
--no-sort do not sort the results
--reverse sort the results in descending order
-p, --precision PRECISION
digits precision of the results, ranging from 1 to 8 (default: 2)
--percentage [{mean,median,min,max,stdev} ...]
statistics showing percentage (default: same as --sort-by)
-f, --file FILE prints the results to a stream (default: the current sys.stdout)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file timeit_compare-1.4.3.tar.gz.
File metadata
- Download URL: timeit_compare-1.4.3.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd0c6e49832f9f005e986d5b29e93eee5ee9335662fada27eedfcdfd60ca6ba8
|
|
| MD5 |
425546c5c60ad567e2a40bd8d143456f
|
|
| BLAKE2b-256 |
b90866eaab3fcb1dde082174e6dd1ed0d7b7efad9468cd156dd7e432ddc20dc8
|
File details
Details for the file timeit_compare-1.4.3-py3-none-any.whl.
File metadata
- Download URL: timeit_compare-1.4.3-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ec0ea88f8ff13eb2d7c134960039f126fed125645305a235b94207e7b3c3f8c
|
|
| MD5 |
9b0d7d4e4b7dce9f7482dc93999643e3
|
|
| BLAKE2b-256 |
5979ab11507e38555ae7531d1445558520901c529636bd590344fe2b784f13cf
|