criterion_compare
Generate markdown comparison tables from Cargo Criterion benchmark output.
Currently, the tool is limited to Github Flavored Markdown (GFM), but adding new output types is simple.
Installation
# If you don't have it already
# This project
Usage
- Ensure your benchmarks meet these basic criteria:
- Benchmark IDs are formatted in two to three sections separated by forward
slashes (
/)- The sections are used like this:
<table_name>/<column_name>/[row_name] - Case is not currently altered, so set appropriately for display
- Row name is the only optional field, and if left blank, all results will be a single blank row
- If using a very basic
benchmark_functionyou would only get a column name, which isn't valid - If using benchmark groups you will get two sections automatically
- If using benchmark groups and
BenchmarkIdyou will get all three sections automatically
- The sections are used like this:
- Benchmark data is not reordered, so ensure they execute in the order desired
- Tables are ordered based on the order they are seen in the data (execution order)
- The first column seen in each row will be the baseline everything else in that row is compared to, so benchmark execution order matters
Benchmark Example 1 - Manual ID
use ;
criterion_group!;
criterion_main!;
Benchmark Example 2 - Benchmark Group with Parameters
use ;
criterion_group!;
criterion_main!;
- Run Benchmarks and Generate Markdown
This can be done in a couple of different ways:
Single Step
This method ensures all benchmarks are included in one step
# Run all benchmarks and convert into the markdown all in one step
|
Multiple Steps
This method allows better control of order and which benchmarks are included
# Execute only the desired benchmarks
# Reorder before converting into markdown
|
Adding New Output File Types
Currently, the tool is hardcoded to GFM, but it is easy to add a new output
type via the Formatter trait by creating your own new binary project
- Add this crate to your binary project as a library
[]
= "0.1"
- Create a new type and implement
criterion_table::Formatter
use ;
use FlexStr;
- Create a
processfunction that takescargo-criterionraw JSON as input and outputs your format as aString:
NOTE: Replace GFMFormatter with your new formatter below
use Error;
use Read;
// This would be replaced with your formatter
use GFMFormatter;
use ;
- Save the returned
Stringto the file type of your formatter
License
This project is licensed optionally under either:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)