Skip to main content

Based on the timeit library, timeit_compare can conveniently measure execution times of multiple statements and provide some basic descriptive statistics to compare the results.

Project description

timeit_compare

Based on the timeit library, timeit_compare can conveniently measure execution times of multiple statements and provide some basic descriptive statistics to compare the results.


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 compare
>>> 
>>> compare(
...     "'-'.join(str(n) for n in range(100))",
...     "'-'.join([str(n) for n in range(100)])",
...     "'-'.join(map(str, range(100)))"
... )
timing now...
|████████████| 15/15 completed
                                 Table 1. Comparison Results (unit: s)                                 
╭────┬───────────────────────────┬─────┬──────────────────────────┬────────┬────────┬────────┬────────╮
│ Id │           Stmt            │ Rpt │          Mean ↓          │ Median │  Min   │  Max   │  Std   │
├────┼───────────────────────────┼─────┼────────┬───────┬─────────┼────────┼────────┼────────┼────────┤
│ 1  │ '-'.join([str(n) for n i… │  5  │ 6.2e-6 │ 74.5% │ █████▎  │ 6.2e-6 │ 6.2e-6 │ 6.2e-6 │ 1.3e-8 │
│ 2  │ '-'.join(map(str, range(… │  5  │ 7.2e-6 │ 86.9% │ ██████▏ │ 7.2e-6 │ 7.2e-6 │ 7.2e-6 │ 1.9e-8 │
│ 0  │ '-'.join(str(n) for n in… │  5  │ 8.3e-6 │ 100.% │ ███████ │ 8.3e-6 │ 8.3e-6 │ 8.3e-6 │ 2.0e-8 │
╰────┴───────────────────────────┴─────┴────────┴───────┴─────────┴────────┴────────┴────────┴────────╯
9225 executions for each statement per repetition                                                      
total execution time 1.0007s                                                                           

The table shows some basic descriptive statistics on the execution time of each statement for comparison, including mean, median, minimum, maximum, and standard deviation.

In a command line interface, call as follows:

python -m timeit_compare -a "'-'.join(str(n) for n in range(100))" -a "'-'.join([str(n) for n in range(100)])" -a "'-'.join(map(str, range(100)))"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timeit_compare-1.3.0.tar.gz (11.4 kB view details)

Uploaded Source

File details

Details for the file timeit_compare-1.3.0.tar.gz.

File metadata

  • Download URL: timeit_compare-1.3.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for timeit_compare-1.3.0.tar.gz
Algorithm Hash digest
SHA256 ce2940b7256ec8c19f50982cf8b42163acf482ea544c34c78a50a275092b4896
MD5 e1020c697a6bd01f658101e7e9c1057e
BLAKE2b-256 c26e8398de32aed79f1e85a75780a7d7b1e250ae3d491c80e99fe5664c6dfa71

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page