Created
August 16, 2023 16:55
-
-
Save ttsugriy/5b4d3c3ea18bbd95371b8711bfb6f4e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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