mirror of
https://github.com/golang/go
synced 2024-11-23 12:20:12 -07:00
runtime: move pinner variable into inner loop for benchmarks
Currently the pinner is created outside of the benchmarking loop. However, this means that we get to reuse the same pinner for each loop; in general, users are expected to create a pinner for a e.g. a cgo call and then that variable will expire with the frame it lives in. (If they can reuse the variable, great! However, I don't expect that to be common.) In essence, this benchmarks a harder case. It's not more right or wrong than the previous version, but the fact that it's a slightly harder case (that still mostly captures what the original version was capturing) is useful. Change-Id: I94987127f54d7bfecd7b8e6a5e632631ea57ad24 Reviewed-on: https://go-review.googlesource.com/c/go/+/497616 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
527d0e8a91
commit
94c75232fb
@ -376,9 +376,9 @@ func BenchmarkPinnerPinUnpinBatch(b *testing.B) {
|
||||
for i := 0; i < Batch; i++ {
|
||||
data[i] = new(obj)
|
||||
}
|
||||
var pinner runtime.Pinner
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
for i := 0; i < Batch; i++ {
|
||||
pinner.Pin(data[i])
|
||||
}
|
||||
@ -392,9 +392,9 @@ func BenchmarkPinnerPinUnpinBatchDouble(b *testing.B) {
|
||||
for i := 0; i < Batch; i++ {
|
||||
data[i] = new(obj)
|
||||
}
|
||||
var pinner runtime.Pinner
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
for i := 0; i < Batch; i++ {
|
||||
pinner.Pin(data[i])
|
||||
pinner.Pin(data[i])
|
||||
@ -409,9 +409,9 @@ func BenchmarkPinnerPinUnpinBatchTiny(b *testing.B) {
|
||||
for i := 0; i < Batch; i++ {
|
||||
data[i] = new(bool)
|
||||
}
|
||||
var pinner runtime.Pinner
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
for i := 0; i < Batch; i++ {
|
||||
pinner.Pin(data[i])
|
||||
}
|
||||
@ -420,27 +420,24 @@ func BenchmarkPinnerPinUnpinBatchTiny(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpin(b *testing.B) {
|
||||
var pinner runtime.Pinner
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
pinner.Pin(new(obj))
|
||||
pinner.Unpin()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpinTiny(b *testing.B) {
|
||||
var pinner runtime.Pinner
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
pinner.Pin(new(bool))
|
||||
pinner.Unpin()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpinDouble(b *testing.B) {
|
||||
var pinner runtime.Pinner
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
var pinner runtime.Pinner
|
||||
p := new(obj)
|
||||
pinner.Pin(p)
|
||||
pinner.Pin(p)
|
||||
@ -449,10 +446,9 @@ func BenchmarkPinnerPinUnpinDouble(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpinParallel(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
var pinner runtime.Pinner
|
||||
for pb.Next() {
|
||||
var pinner runtime.Pinner
|
||||
pinner.Pin(new(obj))
|
||||
pinner.Unpin()
|
||||
}
|
||||
@ -460,10 +456,9 @@ func BenchmarkPinnerPinUnpinParallel(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpinParallelTiny(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
var pinner runtime.Pinner
|
||||
for pb.Next() {
|
||||
var pinner runtime.Pinner
|
||||
pinner.Pin(new(bool))
|
||||
pinner.Unpin()
|
||||
}
|
||||
@ -471,10 +466,9 @@ func BenchmarkPinnerPinUnpinParallelTiny(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkPinnerPinUnpinParallelDouble(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
var pinner runtime.Pinner
|
||||
for pb.Next() {
|
||||
var pinner runtime.Pinner
|
||||
p := new(obj)
|
||||
pinner.Pin(p)
|
||||
pinner.Pin(p)
|
||||
|
Loading…
Reference in New Issue
Block a user