aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/memmove_test.go
diff options
context:
space:
mode:
authornimelehin <nimelehin@gmail.com>2021-12-21 22:45:01 +0300
committerGopher Robot <gobot@golang.org>2022-05-20 13:51:52 +0000
commit5370494577bb0844d3fdfa6bebd27bf9285bb764 (patch)
treee7c19aaeb5abee4caafc134d797d94bdb614d90d /src/runtime/memmove_test.go
parentd8762b2f4532cc2e5ec539670b88bbc469a13938 (diff)
downloadgo-5370494577bb0844d3fdfa6bebd27bf9285bb764.tar.xz
runtime: add BenchmarkMemclrRange
This benchmark is added to test improvements in memclr_amd64. As it is stated in Intel Optimization Manual 15.16.3.3, AVX2-implemented memclr can produce a skewed result with the branch predictor being trained by the large loop iteration count. This benchmark generates sizes between some specified range. This should help to measure how memclr works when branch predictors may be incorrectly trained. Change-Id: I14d173cafe43ca47198ed920e655547a66b3909f Reviewed-on: https://go-review.googlesource.com/c/go/+/373362 Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/runtime/memmove_test.go')
-rw-r--r--src/runtime/memmove_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/runtime/memmove_test.go b/src/runtime/memmove_test.go
index 7c9d2ada45..88873208eb 100644
--- a/src/runtime/memmove_test.go
+++ b/src/runtime/memmove_test.go
@@ -411,6 +411,63 @@ func BenchmarkGoMemclr(b *testing.B) {
})
}
+func BenchmarkMemclrRange(b *testing.B) {
+ type RunData struct {
+ data []int
+ }
+
+ benchSizes := []RunData{
+ RunData{[]int{1043, 1078, 1894, 1582, 1044, 1165, 1467, 1100, 1919, 1562, 1932, 1645,
+ 1412, 1038, 1576, 1200, 1029, 1336, 1095, 1494, 1350, 1025, 1502, 1548, 1316, 1296,
+ 1868, 1639, 1546, 1626, 1642, 1308, 1726, 1665, 1678, 1187, 1515, 1598, 1353, 1237,
+ 1977, 1452, 2012, 1914, 1514, 1136, 1975, 1618, 1536, 1695, 1600, 1733, 1392, 1099,
+ 1358, 1996, 1224, 1783, 1197, 1838, 1460, 1556, 1554, 2020}}, // 1kb-2kb
+ RunData{[]int{3964, 5139, 6573, 7775, 6553, 2413, 3466, 5394, 2469, 7336, 7091, 6745,
+ 4028, 5643, 6164, 3475, 4138, 6908, 7559, 3335, 5660, 4122, 3945, 2082, 7564, 6584,
+ 5111, 2288, 6789, 2797, 4928, 7986, 5163, 5447, 2999, 4968, 3174, 3202, 7908, 8137,
+ 4735, 6161, 4646, 7592, 3083, 5329, 3687, 2754, 3599, 7231, 6455, 2549, 8063, 2189,
+ 7121, 5048, 4277, 6626, 6306, 2815, 7473, 3963, 7549, 7255}}, // 2kb-8kb
+ RunData{[]int{16304, 15936, 15760, 4736, 9136, 11184, 10160, 5952, 14560, 15744,
+ 6624, 5872, 13088, 14656, 14192, 10304, 4112, 10384, 9344, 4496, 11392, 7024,
+ 5200, 10064, 14784, 5808, 13504, 10480, 8512, 4896, 13264, 5600}}, // 4kb-16kb
+ RunData{[]int{164576, 233136, 220224, 183280, 214112, 217248, 228560, 201728}}, // 128kb-256kb
+ }
+
+ for _, t := range benchSizes {
+ total := 0
+ minLen := 0
+ maxLen := 0
+
+ for _, clrLen := range t.data {
+ if clrLen > maxLen {
+ maxLen = clrLen
+ }
+ if clrLen < minLen || minLen == 0 {
+ minLen = clrLen
+ }
+ total += clrLen
+ }
+ buffer := make([]byte, maxLen)
+
+ text := ""
+ if minLen >= (1 << 20) {
+ text = fmt.Sprint(minLen>>20, "M ", (maxLen+(1<<20-1))>>20, "M")
+ } else if minLen >= (1 << 10) {
+ text = fmt.Sprint(minLen>>10, "K ", (maxLen+(1<<10-1))>>10, "K")
+ } else {
+ text = fmt.Sprint(minLen, " ", maxLen)
+ }
+ b.Run(text, func(b *testing.B) {
+ b.SetBytes(int64(total))
+ for i := 0; i < b.N; i++ {
+ for _, clrLen := range t.data {
+ MemclrBytes(buffer[:clrLen])
+ }
+ }
+ })
+ }
+}
+
func BenchmarkClearFat8(b *testing.B) {
for i := 0; i < b.N; i++ {
var x [8 / 4]uint32