critcmp

repository·master·Indexed 42 days ago

https://github.com/burntsushi/critcmp

A command-line tool for comparing benchmark results generated by the Criterion benchmark harness in Rust. It supports interactive, aggregate, and cross-baseline analysis, allowing users to compare multiple baselines, filter results via regex, and group benchmarks using capturing groups. Version 0.1.8 is known to work with Criterion 0.3.3.

Tokens
3.9K
Snippets
18
Records
21
Agent score
53%

What's inside critcmp

  1. Compare Criterion baselines

    master

    The primary use case for critcmp is comparing different Criterion baselines. A baseline is a collection of benchmark data produced by a single Criterion run.

    To compare two baselines, first save them using Criterion's --save-baseline flag, then pass their names to critcmp.

    You can also compare more than two baselines at once.

    # 1. Save baselines using Criterion
    $ cargo bench -- --save-baseline before
    $ cargo bench -- --save-baseline change
    
    # 2. Compare them with critcmp
    $ critcmp before change
    
    # Comparing multiple baselines
    $ critcmp before change1 change2
  2. Compare benchmarks within a single baseline using regex groups

    master

    If you want to compare benchmarks that have different names but represent the same logic (e.g., optimized/input1 vs naive/input1), you can use the -g flag with a regex containing capturing groups.

    critcmp determines the matching criteria based on the values matched by all capturing groups in the regex. Benchmarks with equivalent capturing groups will be grouped into a single comparison.

    # Compare benchmarks in the 'benches' baseline by matching their suffixes
    # This matches 'optimized/input1' and 'naive/input1' via the 'input1' group
    $ critcmp benches -g '\w+/(input1)'
  3. Install critcmp via Cargo

    master

    Since critcmp is designed for use with the Criterion benchmark harness in Rust, install it using cargo install.

    Note on Compatibility:

    • Minimum supported Rust version: The current stable release.
    • Criterion compatibility: Known to work with Criterion 0.3.3.
    • WARNING: This tool reads undocumented internal data emitted by Criterion. It may break if Criterion's internal data format changes.
    $ cargo install critcmp
  4. Filter comparisons by difference threshold

    master

    To hide comparisons where the difference between benchmarks is very small, use the -t or --threshold flag. The value is a percentage.

    Example: To hide any comparisons with differences of 5% or less:

    critcmp before change -t 5
  5. Use critcmp CLI to compare benchmarks

    master

    The critcmp CLI tool is used to compare benchmark results against baselines. It supports grouping benchmarks by baseline, grouping them via regex, filtering results, and setting thresholds for differences.

    Key capabilities include:

    • Listing Baselines: Use the --baselines flag to see available baseline names.
    • Exporting Data: Use the --export <baseline> flag to output the raw benchmark data for a specific baseline in pretty-printed JSON format.
    • Filtering: Use a filter regex to include only specific benchmarks in the comparison.
    • Grouping:
      • By default, benchmarks are grouped by their baseline.
      • Use a regex with capturing groups to group benchmarks into custom categories.
    • Thresholding: Use the --threshold <value> flag to only show comparisons where the biggest difference exceeds the specified value.
    • Output Formats: Results can be displayed in a list format (--list) or a column format (default).
  6. Compare Criterion baselines with critcmp

    master

    The primary use case for critcmp is comparing baselines produced by the Criterion benchmark harness. You can compare two or more baselines by providing their names (as saved by Criterion) or paths to exported JSON files as positional arguments.

    Basic Usage

    To compare two baselines named before and change:

    critcmp before change

    To compare multiple baselines:

    critcmp before change1 change2

    Using Exported JSON Files

    You can export a baseline to a JSON file for permanent storage and then use that file path as an argument:

    critcmp --export before > before.json
    critcmp before.json change
  7. Filter and group benchmarks in critcmp

    master

    When comparing baselines, you can use regex flags to refine which benchmarks are included in the output.

    Filter benchmarks by name

    Use the -f or --filter flag with a regex to only show benchmarks whose names match the pattern:

    critcmp before change -f 'foo.*bar'

    Group benchmarks by regex capturing groups

    Use the -g or --group flag to compare benchmarks that have different names but share common characteristics. This requires a regex with at least one capturing group. Benchmarks are grouped based on the values matched by the capturing groups.

    For example, to compare optimized/input1 and naive/input1 from a baseline named benches:

    critcmp benches -g '\w+/(input1)'
    critcmp before change -f 'foo.*bar'
    critcmp benches -g '\w+/(input1)'
  8. List and export Criterion baselines

    master

    Use critcmp to manage and persist your benchmark data:

    • --baselines: Prints a list of all baselines known to critcmp.
    • --export <BASELINE_NAME>: Exports a specific baseline to a JSON file. This allows you to store benchmark data outside of Criterion's target directory and use it later by referencing the file path.
    # List available baselines
    $ critcmp --baselines
    
    # Export a baseline to JSON
    $ critcmp --export before > before.json
    $ critcmp --export change > change.json
    
    # Use exported JSON files for comparison
    $ critcmp before.json change.json
  9. Filter benchmark comparisons

    master

    You can refine the output of your comparisons using the following flags:

    • -f, --filter <REGEX>: Limit comparisons to benchmarks that match a specific regular expression.
    • -t <THRESHOLD>: Filter out comparisons where the difference is below a certain percentage. For example, -t 5 hides differences of 5% or less.
    • --list: If the default column-oriented display is too wide, use this flag to flatten the results into lists.
    # Filter by regex
    $ critcmp before change -f 'foo.*bar'
    
    # Filter by threshold (e.g., 5%)
    $ critcmp before change -t 5
    
    # Flatten output to lists
    $ critcmp before change1 change2 --list