Commit cbf28ff8 authored by Alberto Donizetti's avatar Alberto Donizetti Committed by Robert Griesemer

strconv: make FormatFloat slowpath a little faster

The relevant benchmark (on an Intel i7-4510U machine):

name                      old time/op  new time/op  delta
FormatFloat/Slowpath64-4  68.6µs ± 0%  44.1µs ± 2%  -35.71%  (p=0.000 n=13+15)

Change-Id: I67eb0e81ce74ed57752d0280059f91419f09e93b
Reviewed-on: https://go-review.googlesource.com/30099Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
parent 77b6a08e
......@@ -131,11 +131,13 @@ func rightShift(a *decimal, k uint) {
}
a.dp -= r - 1
var mask uint = (1 << k) - 1
// Pick up a digit, put down a digit.
for ; r < a.nd; r++ {
c := uint(a.d[r])
dig := n >> k
n -= dig << k
n &= mask
a.d[w] = byte(dig + '0')
w++
n = n*10 + c - '0'
......@@ -144,7 +146,7 @@ func rightShift(a *decimal, k uint) {
// Put down extra digits.
for n > 0 {
dig := n >> k
n -= dig << k
n &= mask
if w < len(a.d) {
a.d[w] = byte(dig + '0')
w++
......
......@@ -208,6 +208,9 @@ var ftoaBenches = []struct {
{"64Fixed2", 123.456, 'e', 3, 64},
{"64Fixed3", 1.23456e+78, 'e', 3, 64},
{"64Fixed4", 1.23456e-78, 'e', 3, 64},
// Trigger slow path (see issue #15672).
{"Slowpath64", 622666234635.3213e-320, 'e', -1, 64},
}
func BenchmarkFormatFloat(b *testing.B) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment