[![crates.io](https://img.shields.io/crates/v/criterion-polyglot.svg)](https://crates.io/crates/criterion-polyglot) [![docs.rs](https://docs.rs/criterion-polyglot/badge.svg)](https://docs.rs/criterion-polyglot/latest) ![Maintenance](https://img.shields.io/badge/maintenance-actively_developed-brightgreen.svg) # criterion-polyglot An extension for [Criterion.rs](https://crates.io/crates/criterion) 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`: ```rust 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`](https://docs.rs/criterion-polyglot/latest/criterion-polyglot/struct.BenchSpec.html) for details. ## Getting Started If you haven't used **Criterion.rs** to benchmark your Rust code before, follow their project's [Quickstart instructions](https://github.com/bheisler/criterion.rs#quickstart), then come back here and follow the synopsis above and the [APIt puj documentation](https://docs.rs/criterion-polyglot/latest) to add polyglot benchmarks to your project.