Marvin Stenger
3c0bf181b7
strconv: simplify and optimize Itoa(small)
...
Use substring of digits for values < 10.
name old time/op new time/op delta
FormatIntSmall/7-4 4.54ns ± 1% 3.70ns ± 1% -18.41% (p=0.000 n=18+17)
FormatIntSmall/42-4 4.54ns ± 1% 4.13ns ± 1% -9.02% (p=0.000 n=16+18)
Change-Id: I0b521b563c13ef88aa2701049fa4a43760e884af
Reviewed-on: https://go-review.googlesource.com/111285
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-03 18:07:02 +00:00
Aliaksandr Valialkin
4c8023bfed
strconv: optimize decimal ints formatting with smallsString
...
Benchmark results for GOARCH=amd64:
name old time/op new time/op delta
FormatInt-4 2.51µs ± 2% 2.40µs ± 2% -4.51% (p=0.000 n=9+10)
AppendInt-4 1.67µs ± 2% 1.61µs ± 3% -3.74% (p=0.000 n=9+9)
FormatUint-4 698ns ± 2% 643ns ± 3% -7.95% (p=0.000 n=10+8)
AppendUint-4 478ns ± 1% 418ns ± 2% -12.61% (p=0.000 n=8+10)
AppendUintVarlen/1-4 9.30ns ± 6% 9.15ns ± 1% ~ (p=0.199 n=9+10)
AppendUintVarlen/12-4 9.12ns ± 0% 9.16ns ± 2% ~ (p=0.307 n=9+9)
AppendUintVarlen/123-4 18.6ns ± 2% 18.7ns ± 0% ~ (p=0.091 n=10+6)
AppendUintVarlen/1234-4 19.1ns ± 4% 17.7ns ± 1% -7.35% (p=0.000 n=10+9)
AppendUintVarlen/12345-4 21.5ns ± 3% 20.7ns ± 3% -3.78% (p=0.002 n=9+10)
AppendUintVarlen/123456-4 23.5ns ± 3% 20.9ns ± 1% -11.14% (p=0.000 n=10+9)
AppendUintVarlen/1234567-4 25.0ns ± 2% 23.6ns ± 7% -5.48% (p=0.004 n=9+10)
AppendUintVarlen/12345678-4 26.8ns ± 2% 23.4ns ± 2% -12.79% (p=0.000 n=9+10)
AppendUintVarlen/123456789-4 29.8ns ± 3% 26.5ns ± 5% -11.03% (p=0.000 n=10+10)
AppendUintVarlen/1234567890-4 31.6ns ± 3% 26.9ns ± 3% -14.95% (p=0.000 n=10+9)
AppendUintVarlen/12345678901-4 33.8ns ± 3% 29.3ns ± 5% -13.21% (p=0.000 n=10+10)
AppendUintVarlen/123456789012-4 35.5ns ± 4% 29.2ns ± 4% -17.82% (p=0.000 n=10+10)
AppendUintVarlen/1234567890123-4 37.6ns ± 4% 31.4ns ± 3% -16.48% (p=0.000 n=10+10)
AppendUintVarlen/12345678901234-4 39.8ns ± 6% 32.0ns ± 7% -19.60% (p=0.000 n=10+10)
AppendUintVarlen/123456789012345-4 40.7ns ± 0% 34.4ns ± 4% -15.55% (p=0.000 n=6+10)
AppendUintVarlen/1234567890123456-4 45.4ns ± 6% 35.1ns ± 4% -22.66% (p=0.000 n=10+10)
AppendUintVarlen/12345678901234567-4 45.1ns ± 1% 36.7ns ± 4% -18.77% (p=0.000 n=9+10)
AppendUintVarlen/123456789012345678-4 46.9ns ± 0% 36.4ns ± 3% -22.49% (p=0.000 n=9+10)
AppendUintVarlen/1234567890123456789-4 50.6ns ± 6% 38.8ns ± 3% -23.28% (p=0.000 n=10+10)
AppendUintVarlen/12345678901234567890-4 51.3ns ± 2% 38.4ns ± 0% -25.00% (p=0.000 n=9+8)
Benchmark results for GOARCH=386:
name old time/op new time/op delta
FormatInt-4 6.21µs ± 0% 6.14µs ± 0% -1.11% (p=0.008 n=5+5)
AppendInt-4 4.95µs ± 0% 4.85µs ± 0% -1.99% (p=0.016 n=5+4)
FormatUint-4 1.89µs ± 1% 1.83µs ± 1% -2.94% (p=0.008 n=5+5)
AppendUint-4 1.59µs ± 0% 1.57µs ± 2% -1.72% (p=0.040 n=5+5)
FormatIntSmall-4 8.48ns ± 0% 8.48ns ± 0% ~ (p=0.905 n=5+5)
AppendIntSmall-4 12.2ns ± 0% 12.2ns ± 0% ~ (all equal)
AppendUintVarlen/1-4 10.6ns ± 1% 10.7ns ± 0% ~ (p=0.238 n=5+4)
AppendUintVarlen/12-4 10.7ns ± 0% 10.7ns ± 1% ~ (p=0.333 n=4+5)
AppendUintVarlen/123-4 29.9ns ± 1% 30.2ns ± 0% +1.07% (p=0.016 n=5+4)
AppendUintVarlen/1234-4 32.4ns ± 1% 30.4ns ± 0% -6.30% (p=0.008 n=5+5)
AppendUintVarlen/12345-4 35.1ns ± 2% 34.9ns ± 0% ~ (p=0.238 n=5+5)
AppendUintVarlen/123456-4 36.6ns ± 0% 35.3ns ± 0% -3.55% (p=0.029 n=4+4)
AppendUintVarlen/1234567-4 38.9ns ± 0% 39.6ns ± 0% +1.80% (p=0.029 n=4+4)
AppendUintVarlen/12345678-4 41.3ns ± 0% 40.1ns ± 0% -2.91% (p=0.000 n=5+4)
AppendUintVarlen/123456789-4 44.9ns ± 1% 44.8ns ± 0% ~ (p=0.667 n=5+5)
AppendUintVarlen/1234567890-4 65.6ns ± 0% 66.2ns ± 1% +0.88% (p=0.016 n=4+5)
AppendUintVarlen/12345678901-4 77.9ns ± 0% 76.3ns ± 0% -2.00% (p=0.000 n=4+5)
AppendUintVarlen/123456789012-4 80.7ns ± 0% 79.1ns ± 1% -2.01% (p=0.008 n=5+5)
AppendUintVarlen/1234567890123-4 83.6ns ± 0% 80.2ns ± 1% -4.07% (p=0.008 n=5+5)
AppendUintVarlen/12345678901234-4 86.2ns ± 1% 83.3ns ± 0% -3.39% (p=0.008 n=5+5)
AppendUintVarlen/123456789012345-4 88.5ns ± 0% 83.7ns ± 0% -5.42% (p=0.008 n=5+5)
AppendUintVarlen/1234567890123456-4 90.6ns ± 0% 88.3ns ± 0% -2.54% (p=0.008 n=5+5)
AppendUintVarlen/12345678901234567-4 92.7ns ± 0% 89.0ns ± 1% -4.01% (p=0.008 n=5+5)
AppendUintVarlen/123456789012345678-4 95.6ns ± 1% 92.6ns ± 0% -3.18% (p=0.016 n=5+4)
AppendUintVarlen/1234567890123456789-4 118ns ± 0% 114ns ± 0% ~ (p=0.079 n=4+5)
AppendUintVarlen/12345678901234567890-4 138ns ± 0% 136ns ± 0% -1.45% (p=0.008 n=5+5)
Updates #19445
Change-Id: Iafbe5c074898187c150dc3854e5b9fc19c10be05
Reviewed-on: https://go-review.googlesource.com/38255
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-22 16:03:28 +00:00
Aliaksandr Valialkin
bc8b9b23ca
strconv: optimize formatting for small decimal ints
...
Avoid memory allocations by returning pre-calculated strings
for decimal ints in the range 0..99.
Benchmark results:
name old time/op new time/op delta
FormatInt-4 2.45µs ± 1% 2.40µs ± 1% -1.86% (p=0.000 n=8+9)
AppendInt-4 1.67µs ± 1% 1.65µs ± 0% -0.92% (p=0.000 n=10+10)
FormatUint-4 676ns ± 3% 669ns ± 1% ~ (p=0.146 n=10+10)
AppendUint-4 467ns ± 2% 474ns ± 0% +1.58% (p=0.000 n=10+10)
FormatIntSmall-4 29.6ns ± 2% 3.3ns ± 0% -88.98% (p=0.000 n=10+9)
AppendIntSmall-4 16.0ns ± 1% 8.5ns ± 0% -46.98% (p=0.000 n=10+9)
name old alloc/op new alloc/op delta
FormatInt-4 576B ± 0% 576B ± 0% ~ (all equal)
AppendInt-4 0.00B 0.00B ~ (all equal)
FormatUint-4 224B ± 0% 224B ± 0% ~ (all equal)
AppendUint-4 0.00B 0.00B ~ (all equal)
FormatIntSmall-4 2.00B ± 0% 0.00B -100.00% (p=0.000 n=10+10)
AppendIntSmall-4 0.00B 0.00B ~ (all equal)
name old allocs/op new allocs/op delta
FormatInt-4 37.0 ± 0% 35.0 ± 0% -5.41% (p=0.000 n=10+10)
AppendInt-4 0.00 0.00 ~ (all equal)
FormatUint-4 6.00 ± 0% 6.00 ± 0% ~ (all equal)
AppendUint-4 0.00 0.00 ~ (all equal)
FormatIntSmall-4 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
AppendIntSmall-4 0.00 0.00 ~ (all equal)
Fixes #19445
Change-Id: Ib1f8922f2e0b13743c847ee9e703d1dab77f705c
Reviewed-on: https://go-review.googlesource.com/37963
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-03-16 19:58:51 +00:00
Martin Möhrmann
0668b595b6
strconv/itoa: add test to generate the longest output string possible by formatBits
...
The new test case produces the longest string representation possible and thereby uses
all of the 65 bytes in the buffer array used by the formatBits function.
Change-Id: I11320c4de56ced5ff098b7e37f1be08e456573e2
Reviewed-on: https://go-review.googlesource.com/2108
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-27 22:35:08 +00:00
Russ Cox
c007ce824d
build: move package sources from src/pkg to src
...
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00