mirror of https://github.com/golang/go.git
runtime/pprof: add label benchmark
Add several benchmarks for pprof labels to analyze the impact of follow-up CLs. Change-Id: Ifae39cfe83ec93858fce9e3af6c1be024ba76736 Reviewed-on: https://go-review.googlesource.com/c/go/+/574515 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
4582f239c3
commit
411ba0ae86
|
|
@ -6,6 +6,7 @@ package pprof
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
|
|
@ -111,3 +112,75 @@ func TestLabelMapStringer(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkLabels(b *testing.B) {
|
||||
b.Run("set-one", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Do(context.Background(), Labels("key", "value"), func(context.Context) {})
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("merge-one", func(b *testing.B) {
|
||||
ctx := WithLabels(context.Background(), Labels("key1", "val1"))
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Do(ctx, Labels("key2", "value2"), func(context.Context) {})
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("overwrite-one", func(b *testing.B) {
|
||||
ctx := WithLabels(context.Background(), Labels("key", "val"))
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Do(ctx, Labels("key", "value"), func(context.Context) {})
|
||||
}
|
||||
})
|
||||
|
||||
for _, scenario := range []string{"ordered", "unordered"} {
|
||||
var labels []string
|
||||
for i := 0; i < 10; i++ {
|
||||
labels = append(labels, fmt.Sprintf("key%03d", i), fmt.Sprintf("value%03d", i))
|
||||
}
|
||||
if scenario == "unordered" {
|
||||
labels[0], labels[len(labels)-1] = labels[len(labels)-1], labels[0]
|
||||
}
|
||||
|
||||
b.Run(scenario, func(b *testing.B) {
|
||||
b.Run("set-many", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Do(context.Background(), Labels(labels...), func(context.Context) {})
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("merge-many", func(b *testing.B) {
|
||||
ctx := WithLabels(context.Background(), Labels(labels[:len(labels)/2]...))
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Do(ctx, Labels(labels[len(labels)/2:]...), func(context.Context) {})
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("overwrite-many", func(b *testing.B) {
|
||||
ctx := WithLabels(context.Background(), Labels(labels...))
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Do(ctx, Labels(labels...), func(context.Context) {})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: hit slow path in Labels
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue