Skip to content

Commit 655152b

Browse files
committed
Benchmark ryu
1 parent 9418169 commit 655152b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ documentation = "https://github.com/dtolnay/dtoa"
99
categories = ["value-formatting"]
1010
readme = "README.md"
1111
exclude = ["performance.png"]
12+
13+
[dev-dependencies]
14+
ryu = { path = "../ryu" }

benches/bench.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ macro_rules! benches {
3838
}
3939
)*
4040
}
41+
42+
mod bench_ryu {
43+
extern crate ryu;
44+
use test::{Bencher, black_box};
45+
$(
46+
#[bench]
47+
fn $name(b: &mut Bencher) {
48+
use std::io::Write;
49+
50+
let mut buf = Vec::with_capacity(20);
51+
52+
b.iter(|| {
53+
buf.clear();
54+
let mut bytes = [0u8; 24];
55+
let n = unsafe { ryu::d2s_buffered_n(black_box($value), &mut bytes[0]) };
56+
buf.write_all(&bytes[..n]).unwrap();
57+
});
58+
}
59+
)*
60+
}
4161
}
4262
}
4363

@@ -47,8 +67,10 @@ benches!(
4767
bench_e_f64(2.718281828459045f64),
4868
bench_max_f64(::std::f64::MAX),
4969

70+
/*
5071
bench_0_f32(0f32),
5172
bench_short_f32(0.1234f32),
5273
bench_e_f32(2.718281828459045f32),
5374
bench_max_f32(::std::f32::MAX),
75+
*/
5476
);

0 commit comments

Comments
 (0)