summaryrefslogtreecommitdiff
path: root/uri-pack/benches/pack.rs
diff options
context:
space:
mode:
Diffstat (limited to 'uri-pack/benches/pack.rs')
-rw-r--r--uri-pack/benches/pack.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/uri-pack/benches/pack.rs b/uri-pack/benches/pack.rs
index e90b818..b7fb975 100644
--- a/uri-pack/benches/pack.rs
+++ b/uri-pack/benches/pack.rs
@@ -10,24 +10,52 @@ fn rand_compat(size: usize) -> String {
.unwrap()
}
+const COMMON: [u8; 31] = [
+ b'a', b'b', b'c', b'd', b'e', b'f', b'g', b'h', b'i', b'j', b'k', b'l', b'm', b'n', b'o', b'p',
+ b'q', b'r', b's', b't', b'u', b'v', b'w', b'x', b'y', b'z', b'.', b'/', b'-', b'_', b'%',
+];
+
+fn rand_simple(size: usize) -> String {
+ String::from_utf8(
+ std::iter::repeat_with(|| COMMON[fastrand::usize(..COMMON.len())])
+ .take(size)
+ .collect(),
+ )
+ .unwrap()
+}
+
fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Uri");
for size in [50, 500, 4048].iter() {
group.throughput(Throughput::Bytes(*size as u64));
- group.bench_with_input(BenchmarkId::new("pack", size), size, |b, &size| {
+ group.bench_with_input(BenchmarkId::new("pack rand", size), size, |b, &size| {
b.iter_batched(
|| rand_compat(size),
|uri| pack_uri(&uri).unwrap(),
criterion::BatchSize::SmallInput,
)
});
- group.bench_with_input(BenchmarkId::new("unpack", size), size, |b, &size| {
+ group.bench_with_input(BenchmarkId::new("unpack rand", size), size, |b, &size| {
b.iter_batched(
|| pack_uri(&rand_compat(size)).unwrap(),
|(packed, len)| unpack_uri(&packed, len),
criterion::BatchSize::SmallInput,
)
});
+ group.bench_with_input(BenchmarkId::new("pack simple", size), size, |b, &size| {
+ b.iter_batched(
+ || rand_simple(size),
+ |uri| pack_uri(&uri).unwrap(),
+ criterion::BatchSize::SmallInput,
+ )
+ });
+ group.bench_with_input(BenchmarkId::new("unpack simple", size), size, |b, &size| {
+ b.iter_batched(
+ || pack_uri(&rand_simple(size)).unwrap(),
+ |(packed, len)| unpack_uri(&packed, len),
+ criterion::BatchSize::SmallInput,
+ )
+ });
}
group.finish();
}