]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: exclude allocation(s) from memmove/memclr benchmarking
authorDmitrii Martynov <fkr011288@gmail.com>
Thu, 30 Jan 2025 18:48:17 +0000 (21:48 +0300)
committerKeith Randall <khr@golang.org>
Sun, 23 Feb 2025 17:38:24 +0000 (09:38 -0800)
The overhead for allocation is not significant but it should be excluded
from the memmove/memclr benchmarking anyway.

Change-Id: I7ea86d1b85b13352ccbff16f7510caa250654dab
Reviewed-on: https://go-review.googlesource.com/c/go/+/645576
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/runtime/memmove_test.go

index 6550c759d637362953bd899595e3ce0818dd098c..ba9bc1f6b6d34ea7acdef7da840ff059926cac1c 100644 (file)
@@ -292,6 +292,7 @@ func BenchmarkMemmove(b *testing.B) {
        benchmarkSizes(b, bufSizes, func(b *testing.B, n int) {
                x := make([]byte, n)
                y := make([]byte, n)
+               b.ResetTimer()
                for i := 0; i < b.N; i++ {
                        copy(x, y)
                }
@@ -301,6 +302,7 @@ func BenchmarkMemmove(b *testing.B) {
 func BenchmarkMemmoveOverlap(b *testing.B) {
        benchmarkSizes(b, bufSizesOverlap, func(b *testing.B, n int) {
                x := make([]byte, n+16)
+               b.ResetTimer()
                for i := 0; i < b.N; i++ {
                        copy(x[16:n+16], x[:n])
                }
@@ -311,6 +313,7 @@ func BenchmarkMemmoveUnalignedDst(b *testing.B) {
        benchmarkSizes(b, bufSizes, func(b *testing.B, n int) {
                x := make([]byte, n+1)
                y := make([]byte, n)
+               b.ResetTimer()
                for i := 0; i < b.N; i++ {
                        copy(x[1:], y)
                }
@@ -320,6 +323,7 @@ func BenchmarkMemmoveUnalignedDst(b *testing.B) {
 func BenchmarkMemmoveUnalignedDstOverlap(b *testing.B) {
        benchmarkSizes(b, bufSizesOverlap, func(b *testing.B, n int) {
                x := make([]byte, n+16)
+               b.ResetTimer()
                for i := 0; i < b.N; i++ {
                        copy(x[16:n+16], x[1:n+1])
                }
@@ -330,6 +334,7 @@ func BenchmarkMemmoveUnalignedSrc(b *testing.B) {
        benchmarkSizes(b, bufSizes, func(b *testing.B, n int) {
                x := make([]byte, n)
                y := make([]byte, n+1)
+               b.ResetTimer()
                for i := 0; i < b.N; i++ {
                        copy(x, y[1:])
                }
@@ -362,6 +367,7 @@ func BenchmarkMemmoveUnalignedSrcDst(b *testing.B) {
 func BenchmarkMemmoveUnalignedSrcOverlap(b *testing.B) {
        benchmarkSizes(b, bufSizesOverlap, func(b *testing.B, n int) {
                x := make([]byte, n+1)
+               b.ResetTimer()
                for i := 0; i < b.N; i++ {
                        copy(x[1:n+1], x[:n])
                }
@@ -450,6 +456,7 @@ func BenchmarkMemclrUnaligned(b *testing.B) {
 func BenchmarkGoMemclr(b *testing.B) {
        benchmarkSizes(b, []int{5, 16, 64, 256}, func(b *testing.B, n int) {
                x := make([]byte, n)
+               b.ResetTimer()
                for i := 0; i < b.N; i++ {
                        clear(x)
                }