mirror of https://github.com/golang/go.git
runtime: move pinned object out of inner loop for benchmarks
In theory by allocating new objects every time, the benchmark is including the performance of allocating new pinner bits for a span. In practice however, most of the time each span already does have pinner bits allocated (it's still a rare operation). We can get a better sense of the raw cost of pinning an object (minus pinner bits allocation) by moving the object allocation out of the inner loop. Change-Id: I2869fa6c3f353b726fe8440d2e6b7f89902f9364 Reviewed-on: https://go-review.googlesource.com/c/go/+/497620 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
ac17bb6f13
commit
5d68121628
|
|
@ -420,25 +420,27 @@ func BenchmarkPinnerPinUnpinBatchTiny(b *testing.B) {
|
|||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpin(b *testing.B) {
|
||||
p := new(obj)
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
pinner.Pin(new(obj))
|
||||
pinner.Pin(p)
|
||||
pinner.Unpin()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpinTiny(b *testing.B) {
|
||||
p := new(bool)
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
pinner.Pin(new(bool))
|
||||
pinner.Pin(p)
|
||||
pinner.Unpin()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpinDouble(b *testing.B) {
|
||||
p := new(obj)
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
p := new(obj)
|
||||
pinner.Pin(p)
|
||||
pinner.Pin(p)
|
||||
pinner.Unpin()
|
||||
|
|
@ -447,9 +449,10 @@ func BenchmarkPinnerPinUnpinDouble(b *testing.B) {
|
|||
|
||||
func BenchmarkPinnerPinUnpinParallel(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
p := new(obj)
|
||||
for pb.Next() {
|
||||
var pinner runtime.Pinner
|
||||
pinner.Pin(new(obj))
|
||||
pinner.Pin(p)
|
||||
pinner.Unpin()
|
||||
}
|
||||
})
|
||||
|
|
@ -457,9 +460,10 @@ func BenchmarkPinnerPinUnpinParallel(b *testing.B) {
|
|||
|
||||
func BenchmarkPinnerPinUnpinParallelTiny(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
p := new(bool)
|
||||
for pb.Next() {
|
||||
var pinner runtime.Pinner
|
||||
pinner.Pin(new(bool))
|
||||
pinner.Pin(p)
|
||||
pinner.Unpin()
|
||||
}
|
||||
})
|
||||
|
|
@ -467,9 +471,9 @@ func BenchmarkPinnerPinUnpinParallelTiny(b *testing.B) {
|
|||
|
||||
func BenchmarkPinnerPinUnpinParallelDouble(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
p := new(obj)
|
||||
for pb.Next() {
|
||||
var pinner runtime.Pinner
|
||||
p := new(obj)
|
||||
pinner.Pin(p)
|
||||
pinner.Pin(p)
|
||||
pinner.Unpin()
|
||||
|
|
|
|||
Loading…
Reference in New Issue