mirror of https://github.com/spf13/viper.git
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 ```
This commit is contained in:
parent
e26d6aedc1
commit
438cc0d5c8
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue