1 unstable release
0.1.0 | Dec 7, 2022 |
---|
#390 in Profiling
55KB
964 lines
criterion-polyglot
An extension for Criterion.rs that provides benchmark methods for various non-Rust programming languages.
Currently Supported Languages
- Python 3
- Ruby
- Go
- Zig
- C
Synopsis
In your crate's benches/benchmark.rs
:
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion_polyglot::{BenchSpec, CriterionPolyglotExt};
fn bench(c: &mut Criterion) {
c.bench_function("in_rust", |b| b.iter(|| {
/* do things in Rust */
}));
c.c_benchmark("in_c", BenchSpec::new(r#"
// do things in C
"#));
c.go_benchmark("in_go", BenchSpec::new(r#"
// Do things in Go
"#).with_imports(r#"
// Import the Go modules you need
"#));
}
criterion_group!(benches, bench);
criterion_main!(benches);
Description
criterion_polyglot::CriterionPolyglotExt
is an extension trait for criterion::Criterion
and
criterion::BenchmarkGroup
that provides methods to benchmark non-Rust programming languages
at the same time as Rust code so that graphs and performance statistics can be compared across
polyglot implementations of the same data structure or algorithm.
criterion_polyglot
provides benchmark harnesses for all the supported languages that can be
filled in with a required, timed code fragment—the benchmark itself—and a variety
of optional, untimed code fragments that initialize data for the benchmark or import modules /
header files that the timed code may require. See the documentation for
criterion_polyglot::BenchSpec
for details.
Getting Started
If you haven't used Criterion.rs to benchmark your Rust code before, follow their project's Quickstart instructions, then come back here and follow the synopsis above and the APIt puj documentation to add polyglot benchmarks to your project.
Dependencies
~8–18MB
~272K SLoC