Add invocation-owned Cobra sessions
This commit is contained in:
@@ -38,6 +38,30 @@ func BenchmarkPerformanceParse(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPerformanceSessionParseAndHelp(b *testing.B) {
|
||||
root := performanceFlatTree(8)
|
||||
args := []string{"wide007"}
|
||||
session := Prepare(root, ParseOptions{Context: context.Background(), Out: io.Discard, Err: io.Discard})
|
||||
result := session.Parse(args)
|
||||
if result.Failure != nil {
|
||||
b.Fatalf("fixture parse failed: %s", result.Failure.Message)
|
||||
}
|
||||
if help, failure := session.RenderHelp(result.Path); failure != nil || help == "" {
|
||||
b.Fatalf("fixture help failed: %q %v", help, failure)
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := session.Parse(args)
|
||||
if result.Failure != nil {
|
||||
b.Fatalf("parse failed: %s", result.Failure.Message)
|
||||
}
|
||||
if help, failure := session.RenderHelp(result.Path); failure != nil || help == "" {
|
||||
b.Fatalf("help failed: %q %v", help, failure)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func performanceFlatTree(count int) *Command {
|
||||
root := &Command{Name: "app", Children: make([]*Command, count)}
|
||||
for index := range root.Children {
|
||||
|
||||
Reference in New Issue
Block a user