From b481d74679b1e1ebdcdd8282d4a8487b89cc5ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 11 May 2022 13:07:20 +0200 Subject: [PATCH] Add a simple ToInt benchmark --- cast_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cast_test.go b/cast_test.go index c254c57..3d93dfb 100644 --- a/cast_test.go +++ b/cast_test.go @@ -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