From 438cc0d5c8791cdfc48adf605914f57c9bb0c29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 26 Sep 2016 10:02:50 +0200 Subject: [PATCH] Add benchmark for GetBool ``` BenchmarkGetBool-4 100000 12952 ns/op 225 B/op 10 allocs/op BenchmarkGetBoolFromMap-4 100000000 10.8 ns/op 0 B/op 0 allocs/op ``` --- viper_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/viper_test.go b/viper_test.go index 127e650..a9f21ea 100644 --- a/viper_test.go +++ b/viper_test.go @@ -918,3 +918,28 @@ func TestShadowedNestedValue(t *testing.T) { assert.Equal(t, GetString("clothing.jacket"), "leather") assert.Equal(t, GetString("clothing.shirt"), polyester) } + +func BenchmarkGetBool(b *testing.B) { + key := "BenchmarkGetBool" + v = New() + v.Set(key, true) + + for i := 0; i < b.N; i++ { + if !v.GetBool(key) { + b.Fatal("GetBool returned false") + } + } +} + +// This is the "perfect result" for the above. +func BenchmarkGetBoolFromMap(b *testing.B) { + m := make(map[string]bool) + key := "BenchmarkGetBool" + m[key] = true + + for i := 0; i < b.N; i++ { + if !m[key] { + b.Fatal("Map value was false") + } + } +}