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:
Bjørn Erik Pedersen 2016-09-26 10:02:50 +02:00
parent e26d6aedc1
commit 438cc0d5c8

View file

@ -918,3 +918,28 @@ func TestShadowedNestedValue(t *testing.T) {
assert.Equal(t, GetString("clothing.jacket"), "leather") assert.Equal(t, GetString("clothing.jacket"), "leather")
assert.Equal(t, GetString("clothing.shirt"), polyester) 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")
}
}
}