runtime: add benchmark of heapBitsSetType

There was an old benchmark that measured this indirectly
via allocation, but I don't understand how to factor out the
allocation cost when interpreting the numbers.

Replace with a benchmark that only calls heapBitsSetType,
that does not allocate. This was not possible when the
benchmark was first written, because heapBitsSetType had
not been factored out of mallocgc.

Change-Id: I30f0f02362efab3465a50769398be859832e6640
Reviewed-on: https://go-review.googlesource.com/9701
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Russ Cox 2015-05-02 22:59:35 -04:00
parent db6f88a84b
commit 7d9e16abc6
2 changed files with 160 additions and 35 deletions

View file

@ -128,3 +128,32 @@ func Envs() []string { return envs }
func SetEnvs(e []string) { envs = e }
var BigEndian = _BigEndian
// For benchmarking.
func BenchSetType(n int, x interface{}) {
e := *(*eface)(unsafe.Pointer(&x))
t := e._type
var size uintptr
var p unsafe.Pointer
switch t.kind & kindMask {
case _KindPtr:
t = (*ptrtype)(unsafe.Pointer(t)).elem
size = t.size
p = e.data
case _KindSlice:
slice := *(*struct {
ptr unsafe.Pointer
len, cap uintptr
})(e.data)
t = (*slicetype)(unsafe.Pointer(t)).elem
size = t.size * slice.len
p = slice.ptr
}
allocSize := roundupsize(size)
systemstack(func() {
for i := 0; i < n; i++ {
heapBitsSetType(uintptr(p), allocSize, size, t)
}
})
}