1
0
mirror of https://github.com/golang/go synced 2024-11-14 23:20:27 -07:00
go/api/next
Lorenz Bauer 04bf36e973 encoding/binary: add Append, Encode and Decode
Add a function which appends the binary representation of a value to the end of a slice.
This allows users to encode values with zero allocations. Also add Encode and Decode
functions which mimic unicode/utf8.

goos: darwin
goarch: arm64
pkg: encoding/binary
cpu: Apple M1 Pro
                            │   base.txt    │             append.txt              │
                            │    sec/op     │    sec/op     vs base               │
ReadSlice1000Int32s-10         2.690µ ±  0%    2.532µ ± 3%   -5.86% (p=0.002 n=6)
ReadStruct-10                  205.8n ±  0%    201.4n ± 1%   -2.14% (p=0.002 n=6)
WriteStruct-10                 159.1n ±  0%    153.5n ± 0%   -3.55% (p=0.002 n=6)
WriteSlice1000Structs-10       129.8µ ±  0%    124.2µ ± 0%   -4.34% (p=0.002 n=6)
ReadSlice1000Structs-10        161.7µ ±  0%    160.3µ ± 0%   -0.89% (p=0.002 n=6)
ReadInts-10                    156.8n ±  0%    161.6n ± 0%   +3.09% (p=0.002 n=6)
WriteInts-10                   134.5n ±  0%    139.5n ± 2%   +3.72% (p=0.002 n=6)
WriteSlice1000Int32s-10        2.691µ ± 16%    2.551µ ± 4%   -5.20% (p=0.002 n=6)
PutUint16-10                  0.6448n ±  4%   0.6212n ± 1%        ~ (p=0.093 n=6)
AppendUint16-10                1.414n ±  0%    1.424n ± 1%        ~ (p=0.115 n=6)
PutUint32-10                  0.6210n ±  0%   0.6211n ± 0%        ~ (p=0.833 n=6)
AppendUint32-10                1.414n ±  0%    1.426n ± 1%   +0.85% (p=0.017 n=6)
PutUint64-10                  0.6210n ±  0%   0.6394n ± 1%   +2.95% (p=0.002 n=6)
AppendUint64-10                1.414n ±  0%    1.427n ± 2%        ~ (p=0.052 n=6)
LittleEndianPutUint16-10      0.6239n ±  0%   0.6271n ± 1%        ~ (p=0.063 n=6)
LittleEndianAppendUint16-10    1.421n ±  0%    1.432n ± 1%   +0.81% (p=0.002 n=6)
LittleEndianPutUint32-10      0.6240n ±  0%   0.6240n ± 0%        ~ (p=0.766 n=6)
LittleEndianAppendUint32-10    1.422n ±  1%    1.425n ± 0%        ~ (p=0.673 n=6)
LittleEndianPutUint64-10      0.6242n ±  0%   0.6238n ± 0%   -0.08% (p=0.030 n=6)
LittleEndianAppendUint64-10    1.420n ±  0%    1.449n ± 1%   +2.04% (p=0.002 n=6)
ReadFloats-10                  39.36n ±  0%    42.54n ± 1%   +8.08% (p=0.002 n=6)
WriteFloats-10                 33.65n ±  0%    35.27n ± 1%   +4.80% (p=0.002 n=6)
ReadSlice1000Float32s-10       2.656µ ±  0%    2.526µ ± 1%   -4.91% (p=0.002 n=6)
WriteSlice1000Float32s-10      2.765µ ±  0%    2.857µ ± 3%   +3.31% (p=0.002 n=6)
ReadSlice1000Uint8s-10         129.1n ±  1%    130.4n ± 1%        ~ (p=0.126 n=6)
WriteSlice1000Uint8s-10       144.90n ±  3%    18.67n ± 2%  -87.12% (p=0.002 n=6)
PutUvarint32-10                12.11n ±  0%    12.12n ± 0%        ~ (p=0.675 n=6)
PutUvarint64-10                30.82n ±  0%    30.79n ± 1%        ~ (p=0.658 n=6)
AppendStruct-10                                107.8n ± 0%
AppendSlice1000Structs-10                      119.0µ ± 0%
AppendInts-10                                  55.29n ± 0%
AppendSlice1000Int32s-10                       2.211µ ± 1%
geomean                        33.07n          48.18n        -7.03%

Fixes #60023

Change-Id: Ife3f217b11d5f3eaa5a53fe8a7e877552f751f94
Reviewed-on: https://go-review.googlesource.com/c/go/+/579157
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Ingo Oeser <nightlyone@googlemail.com>
Reviewed-by: Austin Clements <austin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-20 18:58:26 +00:00
..
42888.txt runtime/debug: eliminate temporary variadicity from SetCrashOutput 2024-05-16 15:19:04 +00:00
44940.txt unicode/utf16: add func RuneLen 2024-03-07 19:08:48 +00:00
46443.txt net/http: add field Cookie.Quoted bool 2024-04-19 00:32:19 +00:00
50102.txt archive/tar: add FileInfoNames interface 2024-03-15 16:01:50 +00:00
53987.txt slices: add Chunk 2024-05-10 17:28:50 +00:00
57151.txt path/filepath: add Localize 2024-02-26 18:08:14 +00:00
59473.txt net/http/httptest: add NewRequestWithContext 2024-03-11 18:09:14 +00:00
60023.txt encoding/binary: add Append, Encode and Decode 2024-05-20 18:58:26 +00:00
60427.txt reflect: add Overflow methods to Type 2024-02-28 14:08:38 +00:00
61308.txt all: add reflect.SliceAt function 2024-04-02 21:51:18 +00:00
61395.txt sync/atomic: public And/Or ops and race instrumentation 2024-05-17 18:37:29 +00:00
61472.txt net/http: add Request.CookiesNamed 2024-03-20 16:17:16 +00:00
61696.txt
61716.txt math/rand/v2: add Uint 2024-05-07 18:03:11 +00:00
61897.txt iter: expose fundamental types to Go 1.23 2024-05-06 20:33:25 +00:00
61899.txt slices: add iterator-related functions 2024-05-09 19:20:55 +00:00
61900.txt maps: add All, Keys, Values, Insert, Collect 2024-05-20 16:01:35 +00:00
62254.txt
62483.txt unique: add unique package and implement Make/Handle 2024-04-22 18:14:07 +00:00
62484.txt
63116.txt net: add Unwrap to *DNSError 2024-04-14 18:23:45 +00:00
65238.txt slices: add func Repeat 2024-03-19 21:38:37 +00:00
65772.txt go/types: add Func.Signature method 2024-04-18 22:17:27 +00:00
66008.txt net/http: add ParseCookie, ParseSetCookie 2024-04-17 17:43:50 +00:00
66054.txt cmd/link,debug/elf: mark Go binaries with no branch target CFI on openbsd 2024-03-10 04:13:26 +00:00
66056.txt reflect: add iterative related methods 2024-05-09 11:54:18 +00:00
66249.txt crypto/x509: add text and binary marshal methods to OID 2024-05-16 02:00:26 +00:00
66339.txt go/ast: add Preorder go1.23 iterator 2024-05-15 21:44:50 +00:00
66405.txt net/http: add Pattern field in Request to return matched pattern info 2024-05-16 18:42:34 +00:00
66559.txt go/types: add Alias.Rhs 2024-04-24 21:50:16 +00:00
66836.txt debug/elf: define non-standard but well-known symbol types 2024-04-16 00:01:16 +00:00
67143.txt go/types, types2: add Alias.{TypeParams, SetTypeParams, TypeArgs, Origin} 2024-05-15 21:32:30 +00:00