mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-12 10:04:29 +02:00
1f5b159161
* Refactor golangci-lint conf Order settings alphabetically. * Add revive settings to golangci conf * Check blank imports * Check bool-literal-in-expr * Check constant-logical-expr * Check context-as-argument * Check context-key-type * Check deep-exit * Check defer * Check dot-imports * Check duplicated-imports * Check early-return * Check empty-block * Check empty-lines * Check error-naming * Check error-return * Check error-strings * Check errorf * Stop ignoring context first arg in tests * Check exported comments * Check flag-parameter * Check identical branches * Check if-return * Check increment-decrement * Check indent-error-flow * Check deny list of go imports * Check import shadowing * Check package comments * Check range * Check range val in closure * Check range val address * Check redefines builtin id * Check string-format * Check struct tag * Check superfluous else * Check time equal * Check var naming * Check var declaration * Check unconditional recursion * Check unexported return * Check unhandled errors * Check unnecessary stmt * Check unnecessary break * Check waitgroup by value * Exclude deep-exit check in example*_test.go files
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package resource_test
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"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)
|
|
}
|