From 4acd98cc7d676c069a54b81ba716841e51a88f1d Mon Sep 17 00:00:00 2001 From: Caleb Spare Date: Sat, 12 Jan 2019 18:51:29 -0800 Subject: [PATCH] Loop over two-digit optimization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a significant speedup in a few cases. name old time/op new time/op delta AppendFloat64/0e+00-12 3.31ns ± 1% 3.29ns ± 1% ~ (p=0.141 n=7+7) AppendFloat64/1e+00-12 14.7ns ± 1% 14.6ns ± 1% ~ (p=0.494 n=7+7) AppendFloat64/3e-01-12 58.7ns ± 1% 51.3ns ± 2% -12.59% (p=0.001 n=7+7) AppendFloat64/1e+06-12 21.2ns ± 0% 21.4ns ± 1% ~ (p=0.182 n=7+7) AppendFloat64/-1.2345e+02-12 58.0ns ± 1% 52.2ns ± 1% -9.95% (p=0.001 n=7+7) AppendFloat64/6.226662346353213e-309-12 48.9ns ± 0% 48.7ns ± 1% ~ (p=0.237 n=6+7) See https://github.com/ulfjack/ryu/issues/85 for discussion. --- ryu64.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ryu64.go b/ryu64.go index 9e93085..87dfb8b 100644 --- a/ryu64.go +++ b/ryu64.go @@ -265,7 +265,7 @@ func float64ToDecimal(mant, exp uint64) dec64 { // Specialized for the common case (~99.3%). // Percentages below are relative to this. roundUp := false - if vp/100 > vm/100 { + for vp/100 > vm/100 { // Optimization: remove two digits at a time (~86.2%). roundUp = vr%100 >= 50 vr /= 100