aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/pprof
diff options
context:
space:
mode:
authorFelix Geisendörfer <felix.geisendoerfer@datadoghq.com>2024-03-26 20:23:30 +0100
committerGopher Robot <gobot@golang.org>2024-11-07 19:24:54 +0000
commit411ba0ae8608a0829a185d83f122d83c8a51c754 (patch)
tree7b096162a1d3d2c858bc4f4a93b21829711a4dc2 /src/runtime/pprof
parent4582f239c3e4589d73dc9e273368f17a196bc09e (diff)
downloadgo-411ba0ae8608a0829a185d83f122d83c8a51c754.tar.xz
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>
Diffstat (limited to 'src/runtime/pprof')
-rw-r--r--src/runtime/pprof/label_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/runtime/pprof/label_test.go b/src/runtime/pprof/label_test.go
index 38d9e80dfc..5cab9f21a5 100644
--- a/src/runtime/pprof/label_test.go
+++ b/src/runtime/pprof/label_test.go
@@ -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
+}