You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-06-23 00:07:52 +02:00
Update to new stdlib apis. The new Float64 is uniform, which resolves a long comment. https://cs.opensource.google/go/go/+/refs/tags/go1.24.2:src/math/rand/v2/rand.go;l=209 > // There are exactly 1<<53 float64s in [0,1). Use Intn(1<<53) / (1<<53). return float64(r.Uint64()<<11>>11) / (1 << 53) ``` goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/sdk/trace cpu: 12th Gen Intel(R) Core(TM) i7-1260P │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ TraceStart/with_a_simple_span-16 387.1n ± 5% 306.8n ± 15% -20.73% (p=0.000 n=10) TraceStart/with_several_links-16 542.2n ± 5% 501.0n ± 2% -7.61% (p=0.000 n=10) TraceStart/with_attributes-16 521.4n ± 14% 571.6n ± 6% +9.64% (p=0.009 n=10) geomean 478.3n 444.6n -7.05% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ TraceStart/with_a_simple_span-16 528.0 ± 0% 528.0 ± 0% ~ (p=1.000 n=10) ¹ TraceStart/with_several_links-16 704.0 ± 0% 704.0 ± 0% ~ (p=1.000 n=10) ¹ TraceStart/with_attributes-16 784.0 ± 0% 784.0 ± 0% ~ (p=1.000 n=10) ¹ geomean 663.0 663.0 +0.00% ¹ all samples are equal │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ TraceStart/with_a_simple_span-16 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ TraceStart/with_several_links-16 3.000 ± 0% 3.000 ± 0% ~ (p=1.000 n=10) ¹ TraceStart/with_attributes-16 4.000 ± 0% 4.000 ± 0% ~ (p=1.000 n=10) ¹ geomean 2.884 2.884 +0.00% ¹ all samples are equal ``` --------- Co-authored-by: Robert Pająk <pellared@hotmail.com> Co-authored-by: Damien Mathieu <42@dmathieu.com>
79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package resource_test
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand/v2"
|
|
"testing"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/sdk/resource"
|
|
)
|
|
|
|
const conflict = 0.5
|
|
|
|
func makeAttrs(n int) (_, _ *resource.Resource) {
|
|
used := map[string]bool{}
|
|
l1 := make([]attribute.KeyValue, n)
|
|
l2 := make([]attribute.KeyValue, n)
|
|
for i := 0; i < n; i++ {
|
|
var k string
|
|
for {
|
|
k = fmt.Sprint("k", rand.IntN(1000000000))
|
|
if !used[k] {
|
|
used[k] = true
|
|
break
|
|
}
|
|
}
|
|
l1[i] = attribute.String(k, fmt.Sprint("v", rand.IntN(1000000000)))
|
|
|
|
if rand.Float64() < conflict {
|
|
l2[i] = l1[i]
|
|
} else {
|
|
l2[i] = attribute.String(k, fmt.Sprint("v", rand.IntN(1000000000)))
|
|
}
|
|
}
|
|
return resource.NewSchemaless(l1...), resource.NewSchemaless(l2...)
|
|
}
|
|
|
|
func benchmarkMergeResource(b *testing.B, size int) {
|
|
r1, r2 := makeAttrs(size)
|
|
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
_, _ = resource.Merge(r1, r2)
|
|
}
|
|
}
|
|
|
|
func BenchmarkMergeResource_1(b *testing.B) {
|
|
benchmarkMergeResource(b, 1)
|
|
}
|
|
|
|
func BenchmarkMergeResource_2(b *testing.B) {
|
|
benchmarkMergeResource(b, 2)
|
|
}
|
|
|
|
func BenchmarkMergeResource_3(b *testing.B) {
|
|
benchmarkMergeResource(b, 3)
|
|
}
|
|
|
|
func BenchmarkMergeResource_4(b *testing.B) {
|
|
benchmarkMergeResource(b, 4)
|
|
}
|
|
|
|
func BenchmarkMergeResource_6(b *testing.B) {
|
|
benchmarkMergeResource(b, 6)
|
|
}
|
|
|
|
func BenchmarkMergeResource_8(b *testing.B) {
|
|
benchmarkMergeResource(b, 8)
|
|
}
|
|
|
|
func BenchmarkMergeResource_16(b *testing.B) {
|
|
benchmarkMergeResource(b, 16)
|
|
}
|