File: benches.rs

package info (click to toggle)
rust-typed-arena 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 148 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 963 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#[macro_use]
extern crate criterion;
extern crate typed_arena;

use criterion::{BenchmarkId, Criterion};

#[derive(Default)]
struct Small(usize);

#[derive(Default)]
struct Big([usize; 32]);

fn allocate<T: Default>(n: usize) {
    let arena = typed_arena::Arena::new();
    for _ in 0..n {
        let val: &mut T = arena.alloc(Default::default());
        criterion::black_box(val);
    }
}

fn criterion_benchmark(c: &mut Criterion) {
    let mut group = c.benchmark_group("allocate");
    for n in 1..5 {
        let n = n * 1000;
        group.throughput(criterion::Throughput::Elements(n as u64));
        group.bench_with_input(BenchmarkId::new("allocate-small", n), &n, |b, &n| {
            b.iter(|| allocate::<Small>(n))
        });
        group.bench_with_input(BenchmarkId::new("allocate-big", n), &n, |b, &n| {
            b.iter(|| allocate::<Big>(n))
        });
    }
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);