Closed
Description
I noticed the following performance cliff of 3 orders of magnitude:
#![feature(test)]
#[cfg(test)]
extern crate test;
#[bench]
fn bench_parse_1e304(b: &mut test::Bencher) {
// Anything under 1e305 is reasonably fast: ~120 ns/iter
b.iter(|| "1.234e304".parse::<f64>());
}
#[bench]
fn bench_parse_1e305(b: &mut test::Bencher) {
// Anything 1e305 or above is slower by 3 orders of magnitude: ~220,000 ns/iter
b.iter(|| "1.234e305".parse::<f64>());
}
Playground that reproduces the same behavior.
I tried Go and it parses both inputs in 60 ns. The resulting bits are the same in both implementations.
package test
import (
"strconv"
"testing"
)
func BenchmarkFast(b *testing.B) {
for n := 0; n < b.N; n++ {
strconv.ParseFloat("1.234e304", 64)
}
}
func BenchmarkAlsoFast(b *testing.B) {
for n := 0; n < b.N; n++ {
strconv.ParseFloat("1.234e305", 64)
}
}