3 ms·
Do you notice any difference if you update `BenchmarkFoundErrorsIs()` to the following? func BenchmarkFoundErrorsIs(b *testing.B) { var es errStore f
by jay-barronville 2y ago
Do you notice any difference if you update `BenchmarkFoundErrorsIs()` to the following?
func BenchmarkFoundErrorsIs(b *testing.B) {
var es errStore
for i := 0; i < b.N; i++ {
val, err := es.GetValue(true)
if err != nil {
if errors.Is(err, notFoundErr) {
b.Fatal("expected found")
} else {
b.Fatal(err)
}
}
if val == nil {
b.Fatal("expected not nil")
}
}
}
- zachmu 2y agoThat's the BenchmarkFoundErrorsIsNilCheck variation, and it eliminates the performance penalty on the happy path. Still just as bad on the error path.
- jay-barronville 2y agoMy apologies! I missed that you covered that variation too. (Good to know it works as I expected though!)