From 0185e558890d3c6c6185044a4d4e747e43c5f813 Mon Sep 17 00:00:00 2001 From: Shyam Jeedigunta Date: Fri, 13 Oct 2017 13:22:10 +0200 Subject: [PATCH] Add benchmark for random string generation utility --- .../k8s.io/apimachinery/pkg/util/rand/rand_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/rand/rand_test.go b/staging/src/k8s.io/apimachinery/pkg/util/rand/rand_test.go index 40fdb7d68d1..7be656c40ac 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/rand/rand_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/rand/rand_test.go @@ -24,6 +24,7 @@ import ( const ( maxRangeTestCount = 500 + testStringLength = 32 ) func TestString(t *testing.T) { @@ -99,3 +100,15 @@ func TestInt63nRange(t *testing.T) { } } } + +func BenchmarkRandomStringGeneration(b *testing.B) { + b.ResetTimer() + var s string + for i := 0; i < b.N; i++ { + s = String(testStringLength) + } + b.StopTimer() + if len(s) == 0 { + b.Fatal(s) + } +}