interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / itoa / benches / bench.rs

41 lines · 1193 bytes Raw Blame History
1use criterion::{criterion_group, criterion_main, Criterion};
2use std::fmt::Display;
3use std::hint;
4use std::io::Write;
5
6fn do_bench(c: &mut Criterion, group_name: &str, int: impl itoa::Integer + Display) {
7 let mut group = c.benchmark_group(group_name);
8 group.bench_function("itoa", |b| {
9 let mut buf = itoa::Buffer::new();
10 b.iter(move || {
11 let int = hint::black_box(int);
12 let formatted = buf.format(int);
13 hint::black_box(formatted);
14 });
15 });
16 group.bench_function("std::fmt", |b| {
17 let mut buf = Vec::with_capacity(20);
18 b.iter(|| {
19 buf.clear();
20 let int = hint::black_box(int);
21 write!(&mut buf, "{int}").unwrap();
22 hint::black_box(buf.as_slice());
23 });
24 });
25 group.finish();
26}
27
28fn bench(c: &mut Criterion) {
29 do_bench(c, "u64[0]", 0u64);
30 do_bench(c, "u64[half]", u64::from(u32::MAX));
31 do_bench(c, "u64[max]", u64::MAX);
32
33 do_bench(c, "i16[0]", 0i16);
34 do_bench(c, "i16[min]", i16::MIN);
35
36 do_bench(c, "u128[0]", 0u128);
37 do_bench(c, "u128[max]", u128::MAX);
38}
39
40criterion_group!(benches, bench);
41criterion_main!(benches);