aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/export_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2015-05-02 22:59:35 -0400
committerRuss Cox <rsc@golang.org>2015-05-11 14:40:27 +0000
commit7d9e16abc6bea2eb12d718b578f91328af99586a (patch)
treef533b106b64b3b8428492a9a917e5befa86927a2 /src/runtime/export_test.go
parentdb6f88a84b126877bd523df8c45af06779ce0e42 (diff)
downloadgo-7d9e16abc6bea2eb12d718b578f91328af99586a.tar.xz
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>
Diffstat (limited to 'src/runtime/export_test.go')
-rw-r--r--src/runtime/export_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go
index 378a68e019..1efe24c61a 100644
--- a/src/runtime/export_test.go
+++ b/src/runtime/export_test.go
@@ -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)
+ }
+ })
+}