Skip to content

Commit 04a9d4d

Browse files
authored
Merge pull request #5 from Alexhuszagh/benches
Add in benchmarks to fast-float-rust
2 parents 36b5ab8 + b5904d4 commit 04a9d4d

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ There are no dependencies and the crate can be used in a no_std context by disab
1919

2020
*Compiler support: rustc 1.37+.*
2121

22+
This crate is in maintenance mode for bug fixes (especially security patches): minimal feature enhancements will be accepted. This implementation has been adopted by the Rust standard library: if you do not need parsing directly from bytes and/or partial parsers, you should use [FromStr](https://doc.rust-lang.org/std/str/trait.FromStr.html) for [f32](https://doc.rust-lang.org/std/primitive.f32.html) or [f64](https://doc.rust-lang.org/std/primitive.f64.html) instead.
23+
2224
## Usage
2325

2426
There's two top-level functions provided:

SECURITY.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Security Policy
2+
3+
This crate is in maintenance mode, so only the latest version is supported and will be receiving bug fixes. If you have a security vulnerability, please reach out to me privately at [[email protected]](mailto:[email protected]). Other forms of communication may not reach me.

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)