#![allow(clippy::clone_on_copy, clippy::useless_conversion, clippy::clone_double_ref)] use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use fast_str::FastStr; pub static FIXTURES: &[(BatchSize, &'static str)] = &[ (BatchSize::SmallInput, "012345678901234"), (BatchSize::LargeInput, "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234"), ]; fn bench_eq(c: &mut Criterion) { let mut group = c.benchmark_group("equals"); for (batch_size, fixture) in FIXTURES.iter().map(Clone::clone) { let len = fixture.len(); group.bench_function(BenchmarkId::new("PartialEq", len), |b| { let fixture = (criterion::black_box(String::from(fixture)), criterion::black_box(fixture)); b.iter_batched(|| &fixture, |(uut1, uut2)| assert!(PartialEq::eq(uut1, uut2)), batch_size) }); group.bench_function(BenchmarkId::new("PartialEq", len), |b| { let fixture = (criterion::black_box(String::from(fixture)), criterion::black_box(String::from(fixture))); b.iter_batched(|| &fixture, |(uut1, uut2)| assert!(PartialEq::eq(uut1, uut2)), batch_size) }); group.bench_function(BenchmarkId::new("PartialEq", len), |b| { let fixture = (criterion::black_box(FastStr::from_ref(fixture)), criterion::black_box(fixture)); b.iter_batched(|| &fixture, |(uut1, uut2)| assert!(PartialEq::eq(uut1, uut2)), batch_size) }); group.bench_function(BenchmarkId::new("PartialEq", len), |b| { let fixture = (criterion::black_box(FastStr::from_static(fixture)), criterion::black_box(fixture)); b.iter_batched(|| &fixture, |(uut1, uut2)| assert!(PartialEq::eq(uut1, uut2)), batch_size) }); group.bench_function(BenchmarkId::new("PartialEq", len), |b| { let fixture = (criterion::black_box(FastStr::from_ref(fixture)), criterion::black_box(FastStr::from_ref(fixture))); b.iter_batched(|| &fixture, |(uut1, uut2)| assert!(PartialEq::eq(uut1, uut2)), batch_size) }); group.bench_function(BenchmarkId::new("PartialEq", len), |b| { let fixture = (criterion::black_box(FastStr::from_static(fixture)), criterion::black_box(FastStr::from_static(fixture))); b.iter_batched(|| &fixture, |(uut1, uut2)| assert!(PartialEq::eq(uut1, uut2)), batch_size) }); } group.finish(); } fn bench_access(c: &mut Criterion) { let mut group = c.benchmark_group("access"); for (batch_size, fixture) in FIXTURES.iter().map(Clone::clone) { let len = fixture.len(); group.bench_function(BenchmarkId::new("String::from", len), |b| { let fixture = criterion::black_box(String::from(fixture)); b.iter_batched(|| &fixture, |uut| uut.len(), batch_size) }); group.bench_function(BenchmarkId::new("FastStr::from_static", len), |b| { let fixture = criterion::black_box(FastStr::from_static(fixture)); b.iter_batched(|| &fixture, |uut| uut.len(), batch_size) }); group.bench_function(BenchmarkId::new("FastStr::from_ref", len), |b| { let fixture = criterion::black_box(FastStr::from_ref(fixture)); b.iter_batched(|| &fixture, |uut| uut.len(), batch_size) }); group.bench_function(BenchmarkId::new("FastStr::from_string", len), |b| { let fixture = criterion::black_box(FastStr::from_string(String::from(fixture))); b.iter_batched(|| &fixture, |uut| uut.len(), batch_size) }); } group.finish(); } fn bench_clone(c: &mut Criterion) { let mut group = c.benchmark_group("clone"); for (batch_size, fixture) in FIXTURES.iter().map(Clone::clone) { let len = fixture.len(); group.bench_function(BenchmarkId::new("String::from", len), |b| { let fixture = criterion::black_box(String::from(fixture)); b.iter_batched(|| &fixture, |uut| uut.clone(), batch_size) }); group.bench_function(BenchmarkId::new("FastStr::from_static", len), |b| { let fixture = criterion::black_box(FastStr::from_static(fixture)); b.iter_batched(|| &fixture, |uut| uut.clone(), batch_size) }); group.bench_function(BenchmarkId::new("FastStr::from_ref", len), |b| { let fixture = criterion::black_box(FastStr::from_ref(fixture)); b.iter_batched(|| &fixture, |uut| uut.clone(), batch_size) }); group.bench_function(BenchmarkId::new("FastStr::from_string", len), |b| { let fixture = criterion::black_box(FastStr::from_string(String::from(fixture))); b.iter_batched(|| &fixture, |uut| uut.clone(), batch_size) }); } group.finish(); } criterion_group!(benches, bench_eq, bench_access, bench_clone); criterion_main!(benches);