Uh oh!
There was an error while loading. Please reload this page.
forked from pkg/errors
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_test.go
More file actions
Latest commit
109 lines (100 loc) · 1.94 KB
/
Copy pathbench_test.go
File metadata and controls
109 lines (100 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// +build go1.13
package errors
import (
goerrors "errors"
"fmt"
"testing"
)
funcnoErrors(at, depthint) error {
ifat>=depth {
returngoerrors.New("no error")
}
returnnoErrors(at+1, depth)
}
funcyesErrors(at, depthint) error {
ifat>=depth {
returnNew("ye error")
}
returnyesErrors(at+1, depth)
}
// GlobalE is an exported global to store the result of benchmark results,
// preventing the compiler from optimising the benchmark functions away.
varGlobalEinterface{}
funcBenchmarkErrors(b*testing.B) {
typerunstruct {
stackint
stdbool
}
runs:= []run{
{10, false},
{10, true},
{100, false},
{100, true},
{1000, false},
{1000, true},
}
for_, r:=rangeruns {
part:="objenious/errors"
ifr.std {
part="errors"
}
name:=fmt.Sprintf("%s-stack-%d", part, r.stack)
b.Run(name, func(b*testing.B) {
varerrerror
f:=yesErrors
ifr.std {
f=noErrors
}
b.ReportAllocs()
fori:=0; i<b.N; i++ {
err=f(0, r.stack)
}
b.StopTimer()
GlobalE=err
})
}
}
funcBenchmarkStackFormatting(b*testing.B) {
typerunstruct {
stackint
formatstring
}
runs:= []run{
{10, "%s"},
{10, "%v"},
{10, "%+v"},
{30, "%s"},
{30, "%v"},
{30, "%+v"},
{60, "%s"},
{60, "%v"},
{60, "%+v"},
}
varstackStrstring
for_, r:=rangeruns {
name:=fmt.Sprintf("%s-stack-%d", r.format, r.stack)
b.Run(name, func(b*testing.B) {
err:=yesErrors(0, r.stack)
b.ReportAllocs()
b.ResetTimer()
fori:=0; i<b.N; i++ {
stackStr=fmt.Sprintf(r.format, err)
}
b.StopTimer()
})
}
for_, r:=rangeruns {
name:=fmt.Sprintf("%s-stacktrace-%d", r.format, r.stack)
b.Run(name, func(b*testing.B) {
err:=yesErrors(0, r.stack)
st:=err.(*withStack).stack.StackTrace()
b.ReportAllocs()
b.ResetTimer()
fori:=0; i<b.N; i++ {
stackStr=fmt.Sprintf(r.format, st)
}
b.StopTimer()
})
}
GlobalE=stackStr
}