Skip to main content

CLI benchmarking tool with rich terminal output and markdown export.

Project description

benchdiff

A CLI benchmarking tool with rich terminal output and markdown export.

Installation

pip install benchdiff

Usage

Create a file named bench_*.py and define a __benchmarks__ list:

# bench_strings.py

words = ["hello", "world", "foo", "bar"]


def concat():
    result = ""
    for w in words:
        result += w


def join():
    "".join(words)


def format_string():
    "%s %s %s %s" % tuple(words)


def fstring():
    f"{words[0]} {words[1]} {words[2]} {words[3]}"


__benchmarks__ = [
    ("String concatenation", [concat, join]),
    ("String formatting", [format_string, fstring]),
]

Run benchmarks:

benchdiff benchmarks/
╭──────────────────────────────── benchdiff ────────────────────────────────╮
│                                                                           │
│   Benchmark                 Min         Median        Max          ×      │
│  ───────────────────────────────────────────────────────────────────────  │
│   String concatenation                                                    │
│     concat                78.333ns     80.833ns     97.750ns    1.711x    │
│     join                  44.250ns     47.250ns     53.125ns    1.000x    │
│   String formatting                                                       │
│     format_string        103.834ns    110.417ns    114.708ns    1.464x    │
│     fstring               75.000ns     75.417ns     76.083ns    1.000x    │
│                                                                           │
│   * times in nanoseconds, lower is better                                 │
│ ───────────────────────────────────────────────────────────────────────── │
│   Python      3.14.2                                                      │
│   Platform    macOS-26.3.1                                                │
│   CPU         Apple M3 Pro                                                │
│   Rounds      5 × 1,000 calls                                             │
│   Date        2026-05-08 10:05:59                                         │
╰───────────────────────────────────────────────────────────────────────────╯

CLI options

benchdiff [PATH] [OPTIONS]

Arguments:
  PATH    Path to search for bench_*.py files [default: .]

Options:
  --repeat    Number of measurement loops [default: 5]
  --times     Number of calls per measurement [default: 1000]
  --markdown  Output as GFM markdown table
  --help      Show this message and exit.

Markdown output

benchdiff benchmarks/ --markdown
Benchmark Min Median Max ×
String concatenation
concat 81.000ns 89.583ns 95.541ns 1.795x
join 43.041ns 49.917ns 50.709ns 1.000x
String formatting
format_string 106.875ns 110.125ns 113.292ns 1.572x
fstring 68.709ns 70.041ns 74.250ns 1.000x

times in nanoseconds, lower is better

Python 3.14.2 · macOS-26.3.1 · Apple M3 Pro · 5 × 1,000 rounds · 2026-05-08 10:05:59

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

benchdiff-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

benchdiff-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file benchdiff-0.1.0.tar.gz.

File metadata

  • Download URL: benchdiff-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for benchdiff-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f4ea102caaeb7bb24147a94e3154be7348f8a3666f47b3548ac24e9499339138
MD5 591e27dc054bf710d16a1be3a18fc9eb
BLAKE2b-256 80c802e9a628a88ce0f3285f6f583f6b9192ae66efc3ee6e42ea23ec85e55604

See more details on using hashes here.

File details

Details for the file benchdiff-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: benchdiff-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for benchdiff-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 312fe480166ff9d88af2213d3d737395d71a90a5ffc9fed8ca6dc26872fb91ef
MD5 ad4d68ee5f5e44c80b114eab58c3b163
BLAKE2b-256 8d9c54bc2435af1c5557d2cc11debe1f8daa31d3b31f4fdc03a53117dcb9f71d

See more details on using hashes here.

Supported by

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