use crate::lib_test::{Timing, Unit}; use format_num_pattern::{fmt_to, format_to, NumberFormat}; use std::fmt::Write; mod lib_test; #[test] fn bench_num() -> Result<(), anyhow::Error> { let mut t = Timing::default() .skip(10) .runs(100000) .unit(Unit::Microsecond); let mut out = String::new(); t.run_proc("std", || { let _s = write!(&mut out, "{:.16}", rand::random::()); out.clear(); }); let mut ryu = ryu::Buffer::new(); t.run_proc("ryu", || { _ = ryu.format(rand::random::()); }); let fmt = NumberFormat::new("0.################")?; let mut out = String::new(); t.run_proc("fmt", || { fmt_to(rand::random::(), &fmt, &mut out); out.clear(); }); let mut out = String::new(); t.run_proc("fmt2", || { _ = format_to(rand::random::(), "0.################", &mut out); out.clear(); }); println!("{}", t); Ok(()) }