Skip to content

Commit

Permalink
Add a simple ToInt benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed May 11, 2022
1 parent 8807572 commit b481d74
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
x := 13
y := &x
Expand Down

0 comments on commit b481d74

Please sign in to comment.