Debian Codegraph @

third_party/rust/dtoa/benches/bench.rs

raw
1 #![feature(test)]
2
3 extern crate dtoa;
4 extern crate test;
5
6 macro_rules! benches {
7 ($($name:ident($value:expr),)*) => {
8 mod bench_dtoa {
9 use test::{Bencher, black_box};
10 $(
11 #[bench]
12 fn $name(b: &mut Bencher) {
13 use dtoa;
14
15 let mut buf = Vec::with_capacity(20);
16
17 b.iter(|| {
18 buf.clear();
19 dtoa::write(&mut buf, black_box($value)).unwrap()
20 });
21 }
22 )*
23 }
24
25 mod bench_fmt {
26 use test::{Bencher, black_box};
27 $(
28 #[bench]
29 fn $name(b: &mut Bencher) {
30 use std::io::Write;
31
32 let mut buf = Vec::with_capacity(20);
33
34 b.iter(|| {
35 buf.clear();
36 write!(&mut buf, "{}", black_box($value)).unwrap()
37 });
38 }
39 )*
40 }
41 }
42 }
43
44 benches!(
45 bench_0_f64(0f64),
46 bench_short_f64(0.1234f64),
47 bench_e_f64(2.718281828459045f64),
48 bench_max_f64(::std::f64::MAX),
49
50 bench_0_f32(0f32),
51 bench_short_f32(0.1234f32),
52 bench_e_f32(2.718281828459045f32),
53 bench_max_f32(::std::f32::MAX),
54 );