From 6f44ae89b1ab4e492516fd8f1770ad16451a9f02 Mon Sep 17 00:00:00 2001 From: wenxuwan Date: Thu, 16 Mar 2023 04:19:40 +0800 Subject: [PATCH] metadata: add benchmark test for FromIncomingContext and ValueFromIncomingContext (#6117) --- metadata/metadata_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go index 57763cd6a973..9277f2d6c84f 100644 --- a/metadata/metadata_test.go +++ b/metadata/metadata_test.go @@ -335,3 +335,21 @@ func BenchmarkFromOutgoingContext(b *testing.B) { FromOutgoingContext(ctx) } } + +func BenchmarkFromIncomingContext(b *testing.B) { + md := Pairs("X-My-Header-1", "42") + ctx := NewIncomingContext(context.Background(), md) + b.ResetTimer() + for n := 0; n < b.N; n++ { + FromIncomingContext(ctx) + } +} + +func BenchmarkValueFromIncomingContext(b *testing.B) { + md := Pairs("X-My-Header-1", "42") + ctx := NewIncomingContext(context.Background(), md) + b.ResetTimer() + for n := 0; n < b.N; n++ { + ValueFromIncomingContext(ctx, "x-my-header-1") + } +}