Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Loop over two-digit optimization.
Browse files Browse the repository at this point in the history
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 ulfjack/ryu#85 for discussion.
  • Loading branch information
cespare committed Jan 13, 2019
1 parent 47b5a18 commit 4639227
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ryu64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4639227

Please sign in to comment.