aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/pkg/errors/bench_test.go
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2017-12-13 10:43:58 -0800
committerChristine Dodrill <me@christine.website>2017-12-13 10:43:58 -0800
commit91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8 (patch)
tree39b7911168d9ffc501894b79842975735bde6c81 /vendor/github.com/pkg/errors/bench_test.go
parent141a3320ff790cbaa52319371de530ae9fd09d89 (diff)
downloadxesite-91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8.tar.xz
xesite-91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8.zip
convert to go buildpack
Diffstat (limited to 'vendor/github.com/pkg/errors/bench_test.go')
-rw-r--r--vendor/github.com/pkg/errors/bench_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/github.com/pkg/errors/bench_test.go b/vendor/github.com/pkg/errors/bench_test.go
new file mode 100644
index 0000000..0416a3c
--- /dev/null
+++ b/vendor/github.com/pkg/errors/bench_test.go
@@ -0,0 +1,59 @@
+// +build go1.7
+
+package errors
+
+import (
+ "fmt"
+ "testing"
+
+ stderrors "errors"
+)
+
+func noErrors(at, depth int) error {
+ if at >= depth {
+ return stderrors.New("no error")
+ }
+ return noErrors(at+1, depth)
+}
+func yesErrors(at, depth int) error {
+ if at >= depth {
+ return New("ye error")
+ }
+ return yesErrors(at+1, depth)
+}
+
+func BenchmarkErrors(b *testing.B) {
+ var toperr error
+ type run struct {
+ stack int
+ std bool
+ }
+ runs := []run{
+ {10, false},
+ {10, true},
+ {100, false},
+ {100, true},
+ {1000, false},
+ {1000, true},
+ }
+ for _, r := range runs {
+ part := "pkg/errors"
+ if r.std {
+ part = "errors"
+ }
+ name := fmt.Sprintf("%s-stack-%d", part, r.stack)
+ b.Run(name, func(b *testing.B) {
+ var err error
+ f := yesErrors
+ if r.std {
+ f = noErrors
+ }
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ err = f(0, r.stack)
+ }
+ b.StopTimer()
+ toperr = err
+ })
+ }
+}