Skip to content

Commit

Permalink
test: Add becnhmark for isAllowedErrAndFunc func
Browse files Browse the repository at this point in the history
  • Loading branch information
psydvl authored and polyfloyd committed Feb 4, 2024
1 parent 0cfe8ce commit c5cc3fb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions errorlint/allowed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,47 @@ func Test_isAllowedErrAndFunc(t *testing.T) {
})
}
}

func Benchmark_isAllowedErrAndFunc(b *testing.B) {
var benchCases = []struct {
desc string
err string
fun string
}{
{
desc: "empty",
err: "",
fun: "",
},
{
desc: "short",
err: "x",
fun: "x",
},
{
desc: "long not existed",
// should pass strings.HasPrefix length check, 30 symbols here
err: "xxxx_xxxx_yyyy_yyyy_zzzz_zzzz_",
fun: "xxxx_xxxx_yyyy_yyyy_zzzz_zzzz_",
},
{
desc: "existed, not wildcard",
err: "io.EOF",
fun: "(io.Reader).Read",
},
{
desc: "existed, wildcard",
err: "golang.org/x/sys/unix.Exx",
fun: "golang.org/x/sys/unix.xxx",
},
}
for _, bb := range benchCases {
b.Run(bb.desc, func(b *testing.B) {
err, fun := bb.err, bb.fun
b.ResetTimer()
for i := 0; i < b.N; i++ {
isAllowedErrAndFunc(err, fun)
}
})
}
}

0 comments on commit c5cc3fb

Please sign in to comment.