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.
|
|
|
|
|
2019-12-24 09:03:04 +02:00
|
|
|
package internal_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel/api/global"
|
|
|
|
"go.opentelemetry.io/otel/api/global/internal"
|
2020-08-18 05:25:03 +02:00
|
|
|
"go.opentelemetry.io/otel/label"
|
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
|
|
|
|
// ../../../sdk/metric/benchmark_test.go to see the overhead of the
|
|
|
|
// global no-op system against a registered SDK.
|
2019-12-24 09:03:04 +02:00
|
|
|
internal.ResetForTest()
|
|
|
|
ctx := context.Background()
|
2020-03-11 17:23:32 +02:00
|
|
|
sdk := global.Meter("test")
|
2020-08-18 05:25:03 +02:00
|
|
|
labs := []label.KeyValue{label.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
|
|
|
|
// ../../../sdk/trace/benchmark_test.go.
|
|
|
|
internal.ResetForTest()
|
|
|
|
t := global.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
|
|
|
}
|
|
|
|
}
|