• Martin Möhrmann's avatar
    strconv: speed up atoi for common cases · 06ed8f0d
    Martin Möhrmann authored
    Add compile time constants for bases 10 and 16 instead of computing the cutoff
    value on every invocation of ParseUint by a division.
    
    Reduce usage of slice operations.
    
    amd64:
    benchmark              old ns/op     new ns/op     delta
    BenchmarkAtoi          44.6          36.0          -19.28%
    BenchmarkAtoiNeg       44.2          38.9          -11.99%
    BenchmarkAtoi64        72.5          56.7          -21.79%
    BenchmarkAtoi64Neg     66.1          58.6          -11.35%
    
    386:
    benchmark              old ns/op     new ns/op     delta
    BenchmarkAtoi          86.6          73.0          -15.70%
    BenchmarkAtoiNeg       86.6          72.3          -16.51%
    BenchmarkAtoi64        126           108           -14.29%
    BenchmarkAtoi64Neg     126           108           -14.29%
    
    Change-Id: I0a271132120d776c97bb4ed1099793c73e159893
    Reviewed-on: https://go-review.googlesource.com/2460Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
    06ed8f0d
atoi.go 4.47 KB