y := typehash(kt, noescape(p), uintptr(mh.hash0))
return x, y
}
+
+func MSpanCountAlloc(bits []byte) int {
+ s := mspan{
+ nelems: uintptr(len(bits) * 8),
+ gcmarkBits: (*gcBits)(unsafe.Pointer(&bits[0])),
+ }
+ return s.countAlloc()
+}
import (
"fmt"
+ "math/rand"
"os"
"reflect"
"runtime"
close(teardown)
}
+func BenchmarkMSpanCountAlloc(b *testing.B) {
+ // n is the number of bytes to benchmark against.
+ // n must always be a multiple of 8, since gcBits is
+ // always rounded up 8 bytes.
+ for _, n := range []int{8, 16, 32, 64, 128} {
+ b.Run(fmt.Sprintf("bits=%d", n*8), func(b *testing.B) {
+ // Initialize a new byte slice with pseduo-random data.
+ bits := make([]byte, n)
+ rand.Read(bits)
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ runtime.MSpanCountAlloc(bits)
+ }
+ })
+ }
+}
+
func countpwg(n *int, ready *sync.WaitGroup, teardown chan bool) {
if *n == 0 {
ready.Done()