-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And benchmark for ong/errors versus other error libraries (#395)
- Loading branch information
Showing
3 changed files
with
69 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package errors | ||
|
||
import ( | ||
stdErrors "errors" | ||
"testing" | ||
|
||
"braces.dev/errtrace" | ||
pkgErrors "github.com/pkg/errors" | ||
) | ||
|
||
var ( | ||
globalStd error //nolint:gochecknoglobals | ||
globalOng error //nolint:gochecknoglobals | ||
globalPkg error //nolint:gochecknoglobals | ||
globalTrace error //nolint:gochecknoglobals | ||
) | ||
|
||
func BenchmarkOtherWrappers(b *testing.B) { | ||
b.Logf("BenchmarkOtherWrappers") | ||
|
||
b.Run("stdError", func(b *testing.B) { | ||
var err error | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
err = stdErrors.New("error") | ||
} | ||
globalStd = err | ||
}) | ||
|
||
b.Run("ongErrors", func(b *testing.B) { | ||
var err error | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
err = New("error") | ||
} | ||
globalOng = err | ||
}) | ||
|
||
b.Run("pkgErrors", func(b *testing.B) { | ||
var err error | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
err = pkgErrors.New("error") | ||
} | ||
globalPkg = err | ||
}) | ||
|
||
b.Run("Errtrace", func(b *testing.B) { | ||
var err error | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
err = errtrace.New("error") | ||
} | ||
globalTrace = err | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters