benchkit
Practical, Documentation-First Benchmarking for Rust.
benchkit
is a lightweight toolkit for performance analysis, born from the hard-learned lessons of optimizing high-performance libraries. It rejects rigid, all-or-nothing frameworks in favor of flexible, composable tools that integrate seamlessly into your existing workflow.
The Benchmarking Dilemma
In Rust, developers often face a frustrating choice:
- The Heavy Framework (
criterion
): Statistically powerful, but forces a rigid structure (benches/
), complex setup, and produces reports that are difficult to integrate into your project's documentation. You must adapt your project to the framework. - The Manual Approach (
std::time
): Simple to start, but statistically naive. It leads to boilerplate, inconsistent measurements, and conclusions that are easily skewed by system noise.
benchkit
offers a third way.
A Toolkit, Not a Framework
This is the core philosophy of benchkit
. It doesn't impose a workflow; it provides a set of professional, composable tools that you can use however you see fit.
- ✅ Integrate Anywhere: Write benchmarks in your test files, examples, or binaries. No required directory structure.
- ✅ Documentation-First: Treat performance reports as a first-class part of your documentation, with tools to automatically keep them in sync with your code.
- ✅ Practical Focus: Surface the key metrics needed for optimization decisions, hiding deep statistical complexity until you ask for it.
- ✅ Zero Setup: Start measuring performance in minutes with a simple, intuitive API.
🚀 Quick Start: Compare, Analyze, and Document
This example demonstrates the core benchkit
workflow: comparing two algorithms and automatically updating a performance section in your README.md
.
1. Add to dev-dependencies
in Cargo.toml
:
[]
= { = "0.1", = [ "full" ] }
2. Create a benchmark in your tests
directory:
// In tests/performance_test.rs
use *;
3. Add a placeholder section to your README.md
:
Old performance data will be replaced here.
4. Run cargo test
:
Your README.md
is automatically updated with a clean, version-controlled report:
- -
🧰 What's in the Toolkit?
benchkit
provides a suite of composable tools. Use only what you need.
At its heart, benchkit
provides simple and accurate measurement primitives.
use *;
// A robust measurement with multiple iterations and statistical cleanup.
let result = bench_function
;
println!;
println!;
// Track memory usage patterns alongside timing.
let memory_benchmark = new;
let = memory_benchmark.run_with_tracking
;
println!;
Turn raw numbers into actionable insights.
use *;
// Compare multiple implementations to find the best one.
let report = new
.algorithm
.algorithm
.run;
if let Some = report.fastest
// Compare performance results like a git diff.
let diff_set = diff_benchmark_sets;
for regression in diff_set.regressions
// Use research-grade statistics when you need high confidence.
let comparison = compare
?;
println!;
Stop writing boilerplate to create test data. benchkit
provides generators for common scenarios.
use *;
// Generate a comma-separated list of 100 items.
let list_data = generate_list_data;
// Generate realistic unilang command strings for parser benchmarking.
let command_generator = new
.complexity;
let commands = command_generator.generate_unilang_commands;
// Create reproducible data with a specific seed.
let mut seeded_gen = new;
let random_data = seeded_gen.random_string;
The "documentation-first" philosophy is enabled by powerful report generation and file updating tools.
use *;
let mut suite = new;
suite.benchmark;
suite.benchmark;
let results = suite.run_analysis;
// Generate a markdown report from the results.
let markdown_report = results.generate_markdown_report.generate;
// Automatically update the "## Performance" section of a file.
let updater = new;
updater.update_section?;
The benchkit
Workflow
benchkit
is designed to make performance analysis a natural part of your development cycle.
[ 1. Write Code ] -> [ 2. Add Benchmark in `tests/` ] -> [ 3. Run `cargo test` ]
^ |
| v
[ 5. Commit Code + Perf Docs ] <- [ 4. Auto-Update `README.md` ] <- [ Analyze Console Results ]
Installation
Add benchkit
to your [dev-dependencies]
in Cargo.toml
.
[]
# For core functionality
= "0.1"
# Or enable all features for the full toolkit
= { = "0.1", = [ "full" ] }
Contributing
Contributions are welcome! benchkit
aims to be a community-driven toolkit that solves real-world benchmarking problems. Please see our contribution guidelines and open tasks.
License
This project is licensed under the MIT License.