Skip to content

Commit

Permalink
reference benchmark to compare how well our err2.Handle is optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Aug 17, 2023
1 parent 8b6f2ea commit c6ee08a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions err2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c6ee08a

Please sign in to comment.