]> Cypherpunks repositories - gostls13.git/commit
math/big: optimize Float.Parse by reducing powers of 10 to powers of 2 and 5
authorRobert Griesemer <gri@golang.org>
Sun, 20 Sep 2015 01:24:16 +0000 (18:24 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 22 Sep 2015 05:48:02 +0000 (05:48 +0000)
commit16b3675bc808095b81ee14dc4f89fb346ff1a0b0
treece91b4c358855e699c2dc1685c8417bdc0a21bf2
parentc396c047c68ce59c67d1ee6d1f6756642b223bae
math/big: optimize Float.Parse by reducing powers of 10 to powers of 2 and 5

Instead of computing the final adjustment factor as a power of 10,
it's more efficient to split 10**e into 2**e * 5**e . Powers of 2
are trivially added to the Float exponent, and powers of 5 are
smaller and thus faster to compute.

Also, use a table of uint64 values rather than float64 values for
initial power value. uint64 values appear to be faster to convert
to Floats (useful for small exponents).

Added two small benchmarks to confirm that there's no regresssion.

benchmark                         old ns/op     new ns/op     delta
BenchmarkParseFloatSmallExp-8     17543         16220         -7.54%
BenchmarkParseFloatLargeExp-8     60865         59996         -1.43%

Change-Id: I3efd7556b023316f86f334137a67fe0c6d52f8ef
Reviewed-on: https://go-review.googlesource.com/14782
Reviewed-by: Alan Donovan <adonovan@google.com>
src/math/big/floatconv.go
src/math/big/floatconv_test.go