Skip to content

Commit b5904d4

Browse files
committed
Add fast-float to the bench comparisons.
1 parent f24b4c8 commit b5904d4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

extras/simple-bench/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ anyhow = "1.0"
1414
lexical = "5.2"
1515
lexical-core = "0.7"
1616
fastrand = "1.4"
17+
fast-float = "0.2"

extras/simple-bench/src/main.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ fn run_bench<T: FastFloat, F: Fn(&str) -> T>(
108108
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
109109
enum Method {
110110
FastFloat,
111+
FastFloat2,
111112
Lexical,
112113
FromStr,
113114
}
@@ -123,23 +124,27 @@ fn type_str(float32: bool) -> &'static str {
123124
impl Method {
124125
pub fn name(&self) -> &'static str {
125126
match self {
127+
Self::FastFloat2 => "fast-float2",
126128
Self::FastFloat => "fast-float",
127129
Self::Lexical => "lexical",
128130
Self::FromStr => "from_str",
129131
}
130132
}
131133

132-
fn run_as<T: FastFloat + FromLexical + FromStr>(
134+
fn run_as<T: FastFloat + fast_float::FastFloat + FromLexical + FromStr>(
133135
&self,
134136
input: &Input,
135137
repeat: usize,
136138
name: &str,
137139
) -> BenchResult {
138140
let data = &input.data;
139141
let times = match self {
140-
Self::FastFloat => run_bench(data, repeat, |s: &str| {
142+
Self::FastFloat2 => run_bench(data, repeat, |s: &str| {
141143
fast_float2::parse_partial::<T, _>(s).unwrap_or_default().0
142144
}),
145+
Self::FastFloat => run_bench(data, repeat, |s: &str| {
146+
fast_float::parse_partial::<T, _>(s).unwrap_or_default().0
147+
}),
143148
Self::Lexical => run_bench(data, repeat, |s: &str| {
144149
lexical_core::parse_partial::<T>(s.as_bytes())
145150
.unwrap_or_default()
@@ -165,7 +170,7 @@ impl Method {
165170
}
166171

167172
pub fn all() -> &'static [Self] {
168-
&[Method::FastFloat, Method::Lexical, Method::FromStr]
173+
&[Method::FastFloat2, Method::FastFloat, Method::Lexical, Method::FromStr]
169174
}
170175
}
171176

@@ -279,7 +284,7 @@ fn main() {
279284
let methods = if !opt.only_fast_float && !matches!(&opt.command, &Cmd::All {..}) {
280285
Method::all().into()
281286
} else {
282-
vec![Method::FastFloat]
287+
vec![Method::FastFloat2]
283288
};
284289

285290
let inputs = match opt.command {

0 commit comments

Comments
 (0)