Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/itoa/benches/bench.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / itoa / benches / bench.rs` 41 lines ยท 1193 bytes Raw Blame History 1 use criterion::{criterion_group, criterion_main, Criterion}; 2 use std::fmt::Display; 3 use std::hint; 4 use std::io::Write; 5 6 fn 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 28 fn 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 40 criterion_group!(benches, bench); 41 criterion_main!(benches);