Crates.io | criterion-polyglot |
lib.rs | criterion-polyglot |
version | 0.1.0 |
source | src |
created_at | 2022-12-07 19:55:00.698336 |
updated_at | 2022-12-07 19:55:00.698336 |
description | An extension trait for criterion providing benchmark methods for various non-Rust programming languages |
homepage | https://codeberg.org/overhacked/criterion-polyglot/ |
repository | https://codeberg.org/overhacked/criterion-polyglot/ |
max_upload_size | |
id | 732105 |
size | 83,004 |
An extension for Criterion.rs that provides benchmark methods for various non-Rust programming languages.
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);
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.
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.