Skip to content

Instantly share code, notes, and snippets.

@robinst
Created April 24, 2018 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinst/a4a6f6223788cc15083d03a4b0c0a7c0 to your computer and use it in GitHub Desktop.
Save robinst/a4a6f6223788cc15083d03a4b0c0a7c0 to your computer and use it in GitHub Desktop.
criterion-with-string-inputs
#[macro_use]
extern crate criterion;
use criterion::{Bencher, Criterion};
fn example(b: &mut Bencher, s: &str) {
b.iter(|| s.len());
}
fn example_benchmark(c: &mut Criterion) {
c.bench_function_over_inputs(
"fun",
|b, s| example(b, s),
vec![
"foo",
"bar/baz"
]
);
}
criterion_group!(benches, example_benchmark);
criterion_main!(benches);
[package]
name = "criterion-test"
version = "0.1.0"
authors = ["Robin Stocker"]
[dev-dependencies]
criterion = "*"
[[bench]]
name = "example"
harness = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment