mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Improve performance of ParseUfloat (#1865)
* Improve performance of ParseUfloat function
Replaced `offset` handling logic with more efficient math.Pow10 based calculation.
goos: linux
goarch: amd64
pkg: github.com/valyala/fasthttp
cpu: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
ParseUfloat-8 44.22n ± 0% 31.06n ± 0% -29.76% (n=50)
* fix: lint error return value is not checked
* Handling uint64 overflow issues
* Implement ParseUfloat by calling strconv.ParseFloat
* fix: lint error
This commit is contained in:
@@ -163,3 +163,27 @@ func BenchmarkAppendUnquotedArgSlowPath(b *testing.B) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkParseUfloat(b *testing.B) {
|
||||
src := [][]byte{
|
||||
[]byte("0"),
|
||||
[]byte("1234566789."),
|
||||
[]byte(".1234556778"),
|
||||
[]byte("123.456"),
|
||||
[]byte("123456789"),
|
||||
[]byte("1234e23"),
|
||||
[]byte("1234E-51"),
|
||||
[]byte("1.234e+32"),
|
||||
[]byte("123456789123456789.987654321"),
|
||||
}
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
for i := range src {
|
||||
_, err := ParseUfloat(src[i])
|
||||
if err != nil {
|
||||
b.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user