2020-03-24 07:41:10 +02:00
|
|
|
// 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.
|
|
|
|
|
2020-11-16 19:30:54 +02:00
|
|
|
package global_test
|
2019-12-24 09:03:04 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2020-11-16 19:30:54 +02:00
|
|
|
"go.opentelemetry.io/otel"
|
2021-02-18 19:59:37 +02:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
2020-11-16 19:30:54 +02:00
|
|
|
"go.opentelemetry.io/otel/internal/global"
|
2021-02-12 18:23:51 +02:00
|
|
|
metricglobal "go.opentelemetry.io/otel/metric/global"
|
2019-12-24 09:03:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
|
2020-07-28 19:47:08 +02:00
|
|
|
// Compare with BenchmarkGlobalInt64CounterAddWithSDK() in
|
2020-11-16 19:30:54 +02:00
|
|
|
// ../../sdk/metric/benchmark_test.go to see the overhead of the
|
2020-07-28 19:47:08 +02:00
|
|
|
// global no-op system against a registered SDK.
|
2020-11-16 19:30:54 +02:00
|
|
|
global.ResetForTest()
|
2019-12-24 09:03:04 +02:00
|
|
|
ctx := context.Background()
|
2021-02-12 18:23:51 +02:00
|
|
|
sdk := metricglobal.Meter("test")
|
2021-02-18 19:59:37 +02:00
|
|
|
labs := []attribute.KeyValue{attribute.String("A", "B")}
|
2020-03-11 20:57:57 +02:00
|
|
|
cnt := Must(sdk).NewInt64Counter("int64.counter")
|
2019-12-24 09:03:04 +02:00
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2020-03-27 23:06:48 +02:00
|
|
|
cnt.Add(ctx, 1, labs...)
|
2019-12-24 09:03:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 19:47:08 +02:00
|
|
|
func BenchmarkStartEndSpanNoSDK(b *testing.B) {
|
|
|
|
// Compare with BenchmarkStartEndSpan() in
|
2020-11-16 19:30:54 +02:00
|
|
|
// ../../sdk/trace/benchmark_test.go.
|
|
|
|
global.ResetForTest()
|
|
|
|
t := otel.Tracer("Benchmark StartEndSpan")
|
2019-12-24 09:03:04 +02:00
|
|
|
ctx := context.Background()
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2020-07-28 19:47:08 +02:00
|
|
|
_, span := t.Start(ctx, "/foo")
|
|
|
|
span.End()
|
2020-01-02 23:20:38 +02:00
|
|
|
}
|
|
|
|
}
|