• Robert Griesemer's avatar
    math/big: optimize Float.Parse by reducing powers of 10 to powers of 2 and 5 · 16b3675b
    Robert Griesemer authored
    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/14782Reviewed-by: 's avatarAlan Donovan <adonovan@google.com>
    16b3675b
floatconv.go 6.93 KB