ryu 0.2.2

Fast floating point to string conversion


Build Status Latest Version Rust Documentation Rustc Version 1.15+




Requirements: this crate supports any compiler version back to rustc 1.15; it uses nothing from the Rust standard library so is usable from no_std crates.

ryu = "0.2"


extern crate ryu;

fn main() {
    let printed = buffer.format(1.234);
    assert_eq!(printed, "1.234");


You can run upstream's benchmarks with:

$ git clone https://github.com/ulfjack/ryu c-ryu
$ cd c-ryu
$ bazel run -c opt //ryu/benchmark

And our benchmarks with:

$ git clone https://github.com/ulfjack/ryu rust-ryu
$ cd rust-ryu
$ cargo run --example benchmark --release

These benchmarks measure the average time to print a 32-bit float and average time to print a 64-bit float, where the inputs are distributed as uniform random bit patterns 32 and 64 bits wide.

The upstream C code, the unsafe direct Rust port, and the safe pretty Rust API all perform the same, taking around 21 nanoseconds to format a 32-bit float and 31 nanoseconds to format a 64-bit float.


Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)