summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/pkg/errors/bench_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-05-17 16:51:25 -0400
committerGitHub <noreply@github.com>2017-05-17 16:51:25 -0400
commitd103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26 (patch)
treedbde13123c6add150448f7b75753ac022d862475 /vendor/github.com/pkg/errors/bench_test.go
parentcd23b8139a9463b67e3096744321f6f4eb0ca40a (diff)
downloadchat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.tar.gz
chat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.tar.bz2
chat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.zip
Upgrading server dependancies (#6431)
Diffstat (limited to 'vendor/github.com/pkg/errors/bench_test.go')
-rw-r--r--vendor/github.com/pkg/errors/bench_test.go63
1 files changed, 63 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 000000000..903b5f2d4
--- /dev/null
+++ b/vendor/github.com/pkg/errors/bench_test.go
@@ -0,0 +1,63 @@
+// +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)
+}
+
+// GlobalE is an exported global to store the result of benchmark results,
+// preventing the compiler from optimising the benchmark functions away.
+var GlobalE error
+
+func BenchmarkErrors(b *testing.B) {
+ 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()
+ GlobalE = err
+ })
+ }
+}