aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc_test.go
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2022-11-10 11:23:40 -0500
committerCherry Mui <cherryyz@google.com>2022-11-10 17:33:31 +0000
commit7717ac151ae1556541dddc6a817ac04733f1af44 (patch)
tree1a3fa557ed1cdf3d0a904938472fde578a80492f /src/runtime/malloc_test.go
parent05cc8b5369b4c3571f0fb2aeed67f9229301b382 (diff)
downloadgo-7717ac151ae1556541dddc6a817ac04733f1af44.tar.xz
runtime: make Malloc benchmarks actually benchmark malloc
The compiler is too clever so the allocations are currently avoided. Rewrite to make them actually allocate. Change-Id: I9542e1365120b2ace318360883b0b01ed5670da7 Reviewed-on: https://go-review.googlesource.com/c/go/+/449476 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/malloc_test.go')
-rw-r--r--src/runtime/malloc_test.go22
1 files changed, 5 insertions, 17 deletions
diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go
index a13f382172..5b9ce9882e 100644
--- a/src/runtime/malloc_test.go
+++ b/src/runtime/malloc_test.go
@@ -318,46 +318,36 @@ func TestArenaCollision(t *testing.T) {
}
}
-var mallocSink uintptr
-
func BenchmarkMalloc8(b *testing.B) {
- var x uintptr
for i := 0; i < b.N; i++ {
p := new(int64)
- x ^= uintptr(unsafe.Pointer(p))
+ Escape(p)
}
- mallocSink = x
}
func BenchmarkMalloc16(b *testing.B) {
- var x uintptr
for i := 0; i < b.N; i++ {
p := new([2]int64)
- x ^= uintptr(unsafe.Pointer(p))
+ Escape(p)
}
- mallocSink = x
}
func BenchmarkMallocTypeInfo8(b *testing.B) {
- var x uintptr
for i := 0; i < b.N; i++ {
p := new(struct {
p [8 / unsafe.Sizeof(uintptr(0))]*int
})
- x ^= uintptr(unsafe.Pointer(p))
+ Escape(p)
}
- mallocSink = x
}
func BenchmarkMallocTypeInfo16(b *testing.B) {
- var x uintptr
for i := 0; i < b.N; i++ {
p := new(struct {
p [16 / unsafe.Sizeof(uintptr(0))]*int
})
- x ^= uintptr(unsafe.Pointer(p))
+ Escape(p)
}
- mallocSink = x
}
type LargeStruct struct {
@@ -365,12 +355,10 @@ type LargeStruct struct {
}
func BenchmarkMallocLargeStruct(b *testing.B) {
- var x uintptr
for i := 0; i < b.N; i++ {
p := make([]LargeStruct, 2)
- x ^= uintptr(unsafe.Pointer(&p[0]))
+ Escape(p)
}
- mallocSink = x
}
var n = flag.Int("n", 1000, "number of goroutines")