Julien Cretel e4fcdc6c55 encoding/{base32,base64}: speed up Encode
This CL clarifies (*Encoding).Encode and speeds it up by reducing the
number of bounds checks in its loop.

Here are some benchmark results (no change to allocations):

goos: darwin
goarch: arm64
pkg: encoding/base32
cpu: Apple M4
                  │     old     │             new              │
                  │   sec/op    │   sec/op     vs base         │
EncodeToString-10   7.310µ ± 0%   5.308µ ± 0%  -27.39% (n=180)
Encode-10           5.651µ ± 0%   3.603µ ± 0%  -36.25% (n=180)
geomean             6.427µ        4.373µ       -31.96%

                  │     old      │                  new                  │
                  │     B/s      │     B/s       vs base                 │
EncodeToString-10   1.044Gi ± 0%   1.437Gi ± 0%  +37.71% (p=0.000 n=180)
Encode-10           1.350Gi ± 0%   2.118Gi ± 0%  +56.88% (p=0.000 n=180)
geomean             1.187Gi        1.745Gi       +46.98%

pkg: encoding/base64
                  │     old     │             new              │
                  │   sec/op    │   sec/op     vs base         │
EncodeToString-10   7.058µ ± 0%   6.034µ ± 0%  -14.51% (n=180)

                  │     old      │                  new                  │
                  │     B/s      │     B/s       vs base                 │
EncodeToString-10   1.081Gi ± 0%   1.264Gi ± 0%  +16.97% (p=0.000 n=180)

Updates #20206

Change-Id: I7d46891ddb4371df004bfd612a8efc6638715b94
GitHub-Last-Rev: 1caac3d655
GitHub-Pull-Request: golang/go#78344
Reviewed-on: https://go-review.googlesource.com/c/go/+/759100
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-26 08:54:47 -07:00
2026-03-06 10:48:32 -08:00
2024-08-09 14:54:31 +00:00
2024-07-22 17:45:27 +00:00

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image Gopher image by Renee French, licensed under Creative Commons 4.0 Attribution license.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Download and Install

Binary Distributions

Official binary distributions are available at https://go.dev/dl/.

After downloading a binary release, visit https://go.dev/doc/install for installation instructions.

Install From Source

If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.

Contributing

Go is the work of thousands of contributors. We appreciate your help!

To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.

Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.

Description
Languages
Go 94.9%
Assembly 4.8%
C 0.1%