...

Source file src/go.opencensus.io/plugin/ocgrpc/benchmark_test.go

Documentation: go.opencensus.io/plugin/ocgrpc

     1  // Copyright 2018, OpenCensus Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ocgrpc
    16  
    17  import (
    18  	"testing"
    19  
    20  	"google.golang.org/grpc/codes"
    21  	"google.golang.org/grpc/status"
    22  )
    23  
    24  func BenchmarkStatusCodeToString_OK(b *testing.B) {
    25  	st := status.New(codes.OK, "OK")
    26  	for i := 0; i < b.N; i++ {
    27  		s := statusCodeToString(st)
    28  		_ = s
    29  	}
    30  }
    31  
    32  func BenchmarkStatusCodeToString_Unauthenticated(b *testing.B) {
    33  	st := status.New(codes.Unauthenticated, "Unauthenticated")
    34  	for i := 0; i < b.N; i++ {
    35  		s := statusCodeToString(st)
    36  		_ = s
    37  	}
    38  }
    39  
    40  var codeToStringMap = map[codes.Code]string{
    41  	codes.OK:                 "OK",
    42  	codes.Canceled:           "CANCELLED",
    43  	codes.Unknown:            "UNKNOWN",
    44  	codes.InvalidArgument:    "INVALID_ARGUMENT",
    45  	codes.DeadlineExceeded:   "DEADLINE_EXCEEDED",
    46  	codes.NotFound:           "NOT_FOUND",
    47  	codes.AlreadyExists:      "ALREADY_EXISTS",
    48  	codes.PermissionDenied:   "PERMISSION_DENIED",
    49  	codes.ResourceExhausted:  "RESOURCE_EXHAUSTED",
    50  	codes.FailedPrecondition: "FAILED_PRECONDITION",
    51  	codes.Aborted:            "ABORTED",
    52  	codes.OutOfRange:         "OUT_OF_RANGE",
    53  	codes.Unimplemented:      "UNIMPLEMENTED",
    54  	codes.Internal:           "INTERNAL",
    55  	codes.Unavailable:        "UNAVAILABLE",
    56  	codes.DataLoss:           "DATA_LOSS",
    57  	codes.Unauthenticated:    "UNAUTHENTICATED",
    58  }
    59  
    60  func BenchmarkMapAlternativeImpl_OK(b *testing.B) {
    61  	st := status.New(codes.OK, "OK")
    62  	for i := 0; i < b.N; i++ {
    63  		_ = codeToStringMap[st.Code()]
    64  	}
    65  }
    66  

View as plain text