Skip to content

Instantly share code, notes, and snippets.

@ttsugriy
Created August 16, 2023 16:55
Show Gist options
  • Save ttsugriy/5b4d3c3ea18bbd95371b8711bfb6f4e3 to your computer and use it in GitHub Desktop.
Save ttsugriy/5b4d3c3ea18bbd95371b8711bfb6f4e3 to your computer and use it in GitHub Desktop.
use criterion::{criterion_group, criterion_main, Criterion};
fn new_with_push(name: &str) -> Vec<&str> {
let mut v = Vec::new();
v.push(name);
v
}
fn new_with_macro(name: &str) -> Vec<&str> {
vec![name]
}
fn bench_new_vecs(c: &mut Criterion) {
let mut group = c.benchmark_group("singleton ve");
let name = "content";
group.bench_function("push", |b| b.iter(|| new_with_push(name)));
group.bench_function("vec!", |b| b.iter(|| new_with_macro(name)));
group.finish();
}
criterion_group!(benches, bench_new_vecs);
criterion_main!(benches);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment