Skip to content

Commit

Permalink
Merge pull request #15 from epage/profile
Browse files Browse the repository at this point in the history
test: Provide a small bench subset
  • Loading branch information
epage committed Sep 29, 2021
2 parents a5bdf63 + 1cf0937 commit 8f4e6dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions benches/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ fn bench_access(c: &mut Criterion) {
for fixture in FIXTURES {
let len = fixture.len();
group.throughput(Throughput::Bytes(len as u64));
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(BenchmarkId::new("&'static str", len), &len, |b, _| {
let uut = *fixture;
let uut = criterion::black_box(uut);
b.iter(|| uut.is_empty())
});
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(BenchmarkId::new("String", len), &len, |b, _| {
let uut = String::from(*fixture);
let uut = criterion::black_box(uut);
Expand All @@ -54,6 +56,7 @@ fn bench_access(c: &mut Criterion) {
let uut = criterion::black_box(uut);
b.iter(|| uut.is_empty())
});
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(BenchmarkId::new("Arc<str>", len), &len, |b, _| {
let uut = std::sync::Arc::<str>::from(*fixture);
let uut = criterion::black_box(uut);
Expand All @@ -73,6 +76,7 @@ fn bench_access(c: &mut Criterion) {
let uut = criterion::black_box(uut);
b.iter(|| uut.is_empty())
});
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(BenchmarkId::new("SmolStr", len), &len, |b, _| {
let uut = smol_str::SmolStr::new(fixture);
let uut = criterion::black_box(uut);
Expand Down Expand Up @@ -101,6 +105,7 @@ fn bench_access(c: &mut Criterion) {
b.iter(|| uut.is_empty())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringCow::from_static", len),
&len,
Expand All @@ -110,6 +115,7 @@ fn bench_access(c: &mut Criterion) {
b.iter(|| uut.is_empty())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringCow::from_ref", len),
&len,
Expand All @@ -119,6 +125,7 @@ fn bench_access(c: &mut Criterion) {
b.iter(|| uut.is_empty())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringCow::from_string", len),
&len,
Expand All @@ -128,6 +135,7 @@ fn bench_access(c: &mut Criterion) {
b.iter(|| uut.is_empty())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringRef::from_static", len),
&len,
Expand All @@ -137,6 +145,7 @@ fn bench_access(c: &mut Criterion) {
b.iter(|| uut.is_empty())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringRef::from_ref", len),
&len,
Expand Down
9 changes: 9 additions & 0 deletions benches/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ fn bench_clone(c: &mut Criterion) {
for fixture in FIXTURES {
let len = fixture.len();
group.throughput(Throughput::Bytes(len as u64));
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(BenchmarkId::new("&'static str", len), &len, |b, _| {
let uut = *fixture;
let uut = criterion::black_box(uut);
b.iter(|| uut.clone())
});
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(BenchmarkId::new("String", len), &len, |b, _| {
let uut = String::from(*fixture);
let uut = criterion::black_box(uut);
Expand All @@ -52,6 +54,7 @@ fn bench_clone(c: &mut Criterion) {
let uut = criterion::black_box(uut);
b.iter(|| uut.clone())
});
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(BenchmarkId::new("Arc<str>", len), &len, |b, _| {
let uut = std::sync::Arc::<str>::from(*fixture);
let uut = criterion::black_box(uut);
Expand All @@ -72,6 +75,7 @@ fn bench_clone(c: &mut Criterion) {
let uut = criterion::black_box(uut);
b.iter(|| uut.clone())
});
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(BenchmarkId::new("SmolStr::new", len), &len, |b, _| {
let uut = smol_str::SmolStr::new(fixture);
let uut = criterion::black_box(uut);
Expand Down Expand Up @@ -102,6 +106,7 @@ fn bench_clone(c: &mut Criterion) {
b.iter(|| uut.clone())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringCow::from_static", len),
&len,
Expand All @@ -111,6 +116,7 @@ fn bench_clone(c: &mut Criterion) {
b.iter(|| uut.clone())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringCow::from_ref", len),
&len,
Expand All @@ -121,6 +127,7 @@ fn bench_clone(c: &mut Criterion) {
b.iter(|| uut.clone())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringCow::from_string", len),
&len,
Expand All @@ -131,6 +138,7 @@ fn bench_clone(c: &mut Criterion) {
b.iter(|| uut.clone())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringRef::from_static", len),
&len,
Expand All @@ -140,6 +148,7 @@ fn bench_clone(c: &mut Criterion) {
b.iter(|| uut.clone())
},
);
#[cfg(not(feature = "bench_subset_unstable"))]
group.bench_with_input(
BenchmarkId::new("KStringRef::from_ref", len),
&len,
Expand Down

0 comments on commit 8f4e6dd

Please sign in to comment.