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/zmij/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 / zmij / benches / bench.rs` 47 lines ยท 1418 bytes Raw Blame History 1 #![allow(clippy::unreadable_literal)] 2 3 use criterion::{criterion_group, criterion_main, Criterion}; 4 use std::f64; 5 use std::hint; 6 use std::io::Write; 7 8 fn do_bench(c: &mut Criterion, group_name: &str, float: f64) { 9 let mut group = c.benchmark_group(group_name); 10 group.bench_function("zmij", |b| { 11 let mut buf = zmij::Buffer::new(); 12 b.iter(move || { 13 let float = hint::black_box(float); 14 let formatted = buf.format_finite(float); 15 hint::black_box(formatted); 16 }); 17 }); 18 group.bench_function("ryu", |b| { 19 let mut buf = ryu::Buffer::new(); 20 b.iter(move || { 21 let float = hint::black_box(float); 22 let formatted = buf.format_finite(float); 23 hint::black_box(formatted); 24 }); 25 }); 26 group.bench_function("std::fmt", |b| { 27 let mut buf = Vec::with_capacity(20); 28 b.iter(|| { 29 buf.clear(); 30 let float = hint::black_box(float); 31 write!(&mut buf, "{float}").unwrap(); 32 hint::black_box(buf.as_slice()); 33 }); 34 }); 35 group.finish(); 36 } 37 38 fn bench(c: &mut Criterion) { 39 do_bench(c, "f64[0]", 0f64); 40 do_bench(c, "f64[short]", 0.`1234f64`); 41 do_bench(c, "f64[medium]", 0.`123456789f64`); 42 do_bench(c, "f64[e]", f64::consts::E); 43 do_bench(c, "f64[max]", f64::MAX); 44 } 45 46 criterion_group!(benches, bench); 47 criterion_main!(benches);