1
0
mirror of https://github.com/golang/go synced 2024-10-05 00:21:21 -06:00
go/src/pkg/runtime/malloc_test.go

53 lines
976 B
Go
Raw Normal View History

// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime_test
import (
"testing"
"unsafe"
)
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))
}
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))
}
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))
}
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))
}
mallocSink = x
}