mirror of
https://github.com/rclone/rclone.git
synced 2024-11-28 03:14:55 +01:00
6427029c4e
* Update all dependencies * Remove all `[[constraint]]` from Gopkg.toml * Add in the minimum number of `[[override]]` to build * Remove go get of github.com/inconshreveable/mousetrap as it is vendored * Update docs with new policy on constraints
60 lines
906 B
Go
60 lines
906 B
Go
// +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
|
|
})
|
|
}
|
|
}
|