From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/bumpalo/benches/benches.rs | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 third_party/rust/bumpalo/benches/benches.rs (limited to 'third_party/rust/bumpalo/benches/benches.rs') diff --git a/third_party/rust/bumpalo/benches/benches.rs b/third_party/rust/bumpalo/benches/benches.rs new file mode 100644 index 0000000000..5f1415f546 --- /dev/null +++ b/third_party/rust/bumpalo/benches/benches.rs @@ -0,0 +1,66 @@ +use criterion::*; + +#[derive(Default)] +struct Small(u8); + +#[derive(Default)] +struct Big([usize; 32]); + +fn alloc(n: usize) { + let arena = bumpalo::Bump::with_capacity(n * std::mem::size_of::()); + for _ in 0..n { + let arena = black_box(&arena); + let val: &mut T = arena.alloc(black_box(Default::default())); + black_box(val); + } +} + +fn alloc_with(n: usize) { + let arena = bumpalo::Bump::with_capacity(n * std::mem::size_of::()); + for _ in 0..n { + let arena = black_box(&arena); + let val: &mut T = arena.alloc_with(|| black_box(Default::default())); + black_box(val); + } +} + +#[cfg(feature = "collections")] +fn format_realloc(bump: &bumpalo::Bump, n: usize) { + let n = criterion::black_box(n); + let s = bumpalo::format!(in bump, "Hello {:.*}", n, "World! "); + criterion::black_box(s); +} + +const ALLOCATIONS: usize = 10_000; + +fn bench_alloc(c: &mut Criterion) { + let mut group = c.benchmark_group("alloc"); + group.throughput(Throughput::Elements(ALLOCATIONS as u64)); + group.bench_function("small", |b| b.iter(|| alloc::(ALLOCATIONS))); + group.bench_function("big", |b| b.iter(|| alloc::(ALLOCATIONS))); +} + +fn bench_alloc_with(c: &mut Criterion) { + let mut group = c.benchmark_group("alloc-with"); + group.throughput(Throughput::Elements(ALLOCATIONS as u64)); + group.bench_function("small", |b| b.iter(|| alloc_with::(ALLOCATIONS))); + group.bench_function("big", |b| b.iter(|| alloc_with::(ALLOCATIONS))); +} + +fn bench_format_realloc(c: &mut Criterion) { + let mut group = c.benchmark_group("format-realloc"); + + for n in (1..5).map(|n| n * n * n * 10) { + group.throughput(Throughput::Elements(n as u64)); + group.bench_with_input(BenchmarkId::new("format-realloc", n), &n, |b, n| { + let mut bump = bumpalo::Bump::new(); + b.iter(|| { + bump.reset(); + format_realloc(&bump, *n); + }); + }); + } +} + +criterion_group!(benches, bench_alloc, bench_alloc_with, bench_format_realloc); +criterion_main!(benches); -- cgit v1.2.3