aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/base32
diff options
context:
space:
mode:
authorIlya Tocar <ilya.tocar@intel.com>2017-08-01 15:12:54 -0500
committerIlya Tocar <ilya.tocar@intel.com>2017-08-14 18:51:14 +0000
commit8b2f84393b50a2ac77ba36f847c52148f98b320f (patch)
tree9e335896a0592a96b00eb4486243d314e4117951 /src/encoding/base32
parent1f8433c66ae945f6d1e4a6bc8c6c5efebeae0dbe (diff)
downloadgo-8b2f84393b50a2ac77ba36f847c52148f98b320f.tar.gz
go-8b2f84393b50a2ac77ba36f847c52148f98b320f.zip
encoding/base32: improve performance in common case
Unroll loop to improve perfromance back to 1.8 level. name old time/op new time/op delta EncodeToString-6 63.0µs ± 3% 51.7µs ± 2% -17.94% (p=0.000 n=10+10) name old speed new speed delta EncodeToString-6 130MB/s ± 3% 159MB/s ± 2% +21.83% (p=0.000 n=10+10) Vs 1.8: EncodeToString-6 54.9µs ± 2% 51.7µs ± 2% -5.95% (p=0.000 n=10+10) name old speed new speed delta EncodeToString-6 149MB/s ± 2% 159MB/s ± 2% +6.32% (p=0.000 n=10+10) Fixes #21262 Change-Id: I41bf7e1f61041781386d16d573bffe1a7173c0c3 Reviewed-on: https://go-review.googlesource.com/52510 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/encoding/base32')
-rw-r--r--src/encoding/base32/base32.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/encoding/base32/base32.go b/src/encoding/base32/base32.go
index bf341b54f3..e72ba74983 100644
--- a/src/encoding/base32/base32.go
+++ b/src/encoding/base32/base32.go
@@ -130,8 +130,19 @@ func (enc *Encoding) Encode(dst, src []byte) {
}
// Encode 5-bit blocks using the base32 alphabet
- for i := 0; i < 8; i++ {
- if len(dst) > i {
+ size := len(dst)
+ if size >= 8 {
+ // Common case, unrolled for extra performance
+ dst[0] = enc.encode[b[0]]
+ dst[1] = enc.encode[b[1]]
+ dst[2] = enc.encode[b[2]]
+ dst[3] = enc.encode[b[3]]
+ dst[4] = enc.encode[b[4]]
+ dst[5] = enc.encode[b[5]]
+ dst[6] = enc.encode[b[6]]
+ dst[7] = enc.encode[b[7]]
+ } else {
+ for i := 0; i < size; i++ {
dst[i] = enc.encode[b[i]]
}
}