Created
September 12, 2020 15:01
-
-
Save yytyd/e0858e4b6c56b16535f0260897dcdf27 to your computer and use it in GitHub Desktop.
f64 の to_string のベンチマーク(通常の to_string vs Ryu を使った to_string)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(test)] | |
fn main() { | |
println!("Hello, world!"); | |
} | |
fn from_f64_to_string(value: f64) -> String { | |
value.to_string() | |
} | |
fn from_f64_to_string_by_ryu(value: f64) -> String { | |
let mut buffer = ryu::Buffer::new(); | |
let printed = buffer.format(value); | |
printed.to_string() | |
} | |
fn from_i64_to_string(value: i64) -> String { | |
value.to_string() | |
} | |
#[cfg(test)] | |
mod tests { | |
extern crate test; | |
use super::*; | |
use test::Bencher; | |
// 適切に比較できているのかは自信ない… | |
#[bench] | |
fn bench_f64_to_string(b: &mut Bencher) { | |
b.iter(|| from_f64_to_string(1.23)); | |
} | |
#[bench] | |
fn bench_f64_to_string_by_ryu(b: &mut Bencher) { | |
b.iter(|| from_f64_to_string_by_ryu(1.23)); | |
} | |
#[bench] | |
fn bench_i64_to_string(b: &mut Bencher) { | |
b.iter(|| from_i64_to_string(123)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment