diff options
| author | Martin Möhrmann <martisch@uos.de> | 2016-04-10 17:32:35 +0200 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2016-04-10 23:39:46 +0000 |
| commit | ad7448fe982d83de15deec9c55c56d0cd9261c6c (patch) | |
| tree | e4d44cc145b562c0b1e184a4a5d2bec78b8cdfd3 /src/runtime/append_test.go | |
| parent | 5b3e5766bcc5e1090d0512a5916886ffc24ab246 (diff) | |
| download | go-ad7448fe982d83de15deec9c55c56d0cd9261c6c.tar.xz | |
runtime: speed up makeslice by avoiding divisions
Only compute the number of maximum allowed elements per slice once.
name old time/op new time/op delta
MakeSlice-2 55.5ns ± 1% 45.6ns ± 2% -17.88% (p=0.000 n=99+100)
Change-Id: I951feffda5d11910a75e55d7e978d306d14da2c5
Reviewed-on: https://go-review.googlesource.com/21801
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/append_test.go')
| -rw-r--r-- | src/runtime/append_test.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/runtime/append_test.go b/src/runtime/append_test.go index 3170870b0e..6d7836a351 100644 --- a/src/runtime/append_test.go +++ b/src/runtime/append_test.go @@ -7,6 +7,14 @@ import "testing" const N = 20 +func BenchmarkMakeSlice(b *testing.B) { + var x []byte + for i := 0; i < b.N; i++ { + x = make([]byte, 32) + _ = x + } +} + func BenchmarkGrowSliceBytes(b *testing.B) { b.StopTimer() var x = make([]byte, 9) |
