MCPcopy Index your code
hub / github.com/pkg/errors / BenchmarkStackFormatting

Function BenchmarkStackFormatting

bench_test.go:65–110  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

63}
64
65func BenchmarkStackFormatting(b *testing.B) {
66 type run struct {
67 stack int
68 format string
69 }
70 runs := []run{
71 {10, "%s"},
72 {10, "%v"},
73 {10, "%+v"},
74 {30, "%s"},
75 {30, "%v"},
76 {30, "%+v"},
77 {60, "%s"},
78 {60, "%v"},
79 {60, "%+v"},
80 }
81
82 var stackStr string
83 for _, r := range runs {
84 name := fmt.Sprintf("%s-stack-%d", r.format, r.stack)
85 b.Run(name, func(b *testing.B) {
86 err := yesErrors(0, r.stack)
87 b.ReportAllocs()
88 b.ResetTimer()
89 for i := 0; i < b.N; i++ {
90 stackStr = fmt.Sprintf(r.format, err)
91 }
92 b.StopTimer()
93 })
94 }
95
96 for _, r := range runs {
97 name := fmt.Sprintf("%s-stacktrace-%d", r.format, r.stack)
98 b.Run(name, func(b *testing.B) {
99 err := yesErrors(0, r.stack)
100 st := err.(*fundamental).stack.StackTrace()
101 b.ReportAllocs()
102 b.ResetTimer()
103 for i := 0; i < b.N; i++ {
104 stackStr = fmt.Sprintf(r.format, st)
105 }
106 b.StopTimer()
107 })
108 }
109 GlobalE = stackStr
110}

Callers

nothing calls this directly

Calls 2

yesErrorsFunction · 0.85
StackTraceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…