Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ There are no dependencies and the crate can be used in a no_std context by disab

*Compiler support: rustc 1.37+.*

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.

## Usage

There's two top-level functions provided:
Expand Down
3 changes: 3 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

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 [ahuszagh@gmail.com](mailto:ahuszagh@gmail.com). Other forms of communication may not reach me.
1 change: 1 addition & 0 deletions extras/simple-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ anyhow = "1.0"
lexical = "5.2"
lexical-core = "0.7"
fastrand = "1.4"
fast-float = "0.2"
13 changes: 9 additions & 4 deletions extras/simple-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fn run_bench<T: FastFloat, F: Fn(&str) -> T>(
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum Method {
FastFloat,
FastFloat2,
Lexical,
FromStr,
}
Expand All @@ -123,23 +124,27 @@ fn type_str(float32: bool) -> &'static str {
impl Method {
pub fn name(&self) -> &'static str {
match self {
Self::FastFloat2 => "fast-float2",
Self::FastFloat => "fast-float",
Self::Lexical => "lexical",
Self::FromStr => "from_str",
}
}

fn run_as<T: FastFloat + FromLexical + FromStr>(
fn run_as<T: FastFloat + fast_float::FastFloat + FromLexical + FromStr>(
&self,
input: &Input,
repeat: usize,
name: &str,
) -> BenchResult {
let data = &input.data;
let times = match self {
Self::FastFloat => run_bench(data, repeat, |s: &str| {
Self::FastFloat2 => run_bench(data, repeat, |s: &str| {
fast_float2::parse_partial::<T, _>(s).unwrap_or_default().0
}),
Self::FastFloat => run_bench(data, repeat, |s: &str| {
fast_float::parse_partial::<T, _>(s).unwrap_or_default().0
}),
Self::Lexical => run_bench(data, repeat, |s: &str| {
lexical_core::parse_partial::<T>(s.as_bytes())
.unwrap_or_default()
Expand All @@ -165,7 +170,7 @@ impl Method {
}

pub fn all() -> &'static [Self] {
&[Method::FastFloat, Method::Lexical, Method::FromStr]
&[Method::FastFloat2, Method::FastFloat, Method::Lexical, Method::FromStr]
}
}

Expand Down Expand Up @@ -279,7 +284,7 @@ fn main() {
let methods = if !opt.only_fast_float && !matches!(&opt.command, &Cmd::All {..}) {
Method::all().into()
} else {
vec![Method::FastFloat]
vec![Method::FastFloat2]
};

let inputs = match opt.command {
Expand Down
Loading