From c6ee08ace539888541efa7795b235bc6a4903810 Mon Sep 17 00:00:00 2001 From: Harri Lainio Date: Tue, 8 Aug 2023 19:41:50 +0300 Subject: [PATCH] reference benchmark to compare how well our err2.Handle is optimized --- err2_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/err2_test.go b/err2_test.go index 0eee2b4..b15944e 100644 --- a/err2_test.go +++ b/err2_test.go @@ -638,6 +638,28 @@ func BenchmarkRecursionWithTryCall(b *testing.B) { } } +func BenchmarkRecursionWithTryAnd_Empty_Defer(b *testing.B) { + var recursion func(a int) (r int, err error) + recursion = func(a int) (r int, err error) { + defer func(e error) { // try to be as close to our case, but simple! + err = e + }(err) + + if a == 0 { + return 0, nil + } + s := try.To1(noThrow()) + _ = s + r = try.To1(recursion(a - 1)) + r += a + return r, nil + } + + for n := 0; n < b.N; n++ { + _, _ = recursion(100) + } +} + func BenchmarkRecursionWithTryAndDefer(b *testing.B) { var recursion func(a int) (r int, err error) recursion = func(a int) (r int, err error) {