Add a simple ToInt benchmark

This commit is contained in:
Bjørn Erik Pedersen 2022-05-11 13:07:20 +02:00
parent 88075729b0
commit b481d74679
No known key found for this signature in database
GPG Key ID: 330E6E2BD4859D8F
1 changed files with 13 additions and 0 deletions

View File

@ -1174,6 +1174,19 @@ func BenchmarkTooBool(b *testing.B) {
} }
} }
func BenchmarkTooInt(b *testing.B) {
convert := func(num52 interface{}) {
if v := ToInt(num52); v != 52 {
b.Fatalf("ToInt returned wrong value, got %d, want %d", v, 32)
}
}
for i := 0; i < b.N; i++ {
convert("52")
convert(52.0)
convert(uint64(52))
}
}
func TestIndirectPointers(t *testing.T) { func TestIndirectPointers(t *testing.T) {
x := 13 x := 13
y := &x y := &x