...
1
2
3
4
5
6
7
8
9
10
11
12
13
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