[−][src]Module lexical::ftoa
Fast lexical float-to-string conversion routines.
The optimized routines are adapted from Andrea Samoljuk's fpconv
library,
which is available here.
The radix-generic algorithm is adapted from the V8 codebase, and may be found here.
The following benchmarks were run on an "Intel(R) Core(TM) i7-6560U
CPU @ 2.20GHz" CPU, on Fedora 28, Linux kernel version 4.18.16-200
(x86-64), using the lexical formatter, dtoa::write()
or x.to_string()
,
avoiding any inefficiencies in Rust string parsing for format!(...)
or write!()
macros. The code was compiled with LTO and at an optimization
level of 3.
The benchmarks with std
were compiled using "rustc 1.29.2 (17a9dc751
2018-10-05", and the no_std
benchmarks were compiled using "rustc
1.31.0-nightly (46880f41b 2018-10-15)".
The benchmark code may be found benches/ftoa.rs
.
Benchmarks
Type | lexical (ns/iter) | to_string (ns/iter) | Relative Increase |
---|---|---|---|
f32 | 1,221,025 | 2,711,290 | 2.22x |
f64 | 1,248,397 | 3,558,305 | 2.85x |
Raw Benchmarks
test f32_dtoa ... bench: 1,301,173 ns/iter (+/- 45,283)
test f32_lexical ... bench: 1,221,025 ns/iter (+/- 42,428)
test f32_to_string ... bench: 2,711,290 ns/iter (+/- 75,376)
test f64_dtoa ... bench: 1,462,523 ns/iter (+/- 103,974)
test f64_lexical ... bench: 1,248,397 ns/iter (+/- 41,952)
test f64_to_string ... bench: 3,558,305 ns/iter (+/- 103,945)
Raw Benchmarks (no_std
)
test f32_dtoa ... bench: 1,727,839 ns/iter (+/- 76,330)
test f32_lexical ... bench: 1,461,892 ns/iter (+/- 95,811)
test f32_to_string ... bench: 3,687,219 ns/iter (+/- 313,885)
test f64_dtoa ... bench: 1,927,419 ns/iter (+/- 122,000)
test f64_lexical ... bench: 1,505,955 ns/iter (+/- 87,548)
test f64_to_string ... bench: 4,774,595 ns/iter (+/- 244,214)
Functions
exponent_notation_char |
Get the exponent notation character. |
f32toa_unsafe⚠ |
Unsafe, C-like exporter for float numbers. |
f32toa_string |
Low-level string exporter for numbers. |
f64toa_unsafe⚠ |
Unsafe, C-like exporter for float numbers. |
f64toa_string |
Low-level string exporter for numbers. |