From fb1f39915d092e6ecbdb38c0861170bdf4416800 Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Sun, 14 May 2017 14:57:11 +0200 Subject: [PATCH] Add benchmark for GenBashCompletion --- bash_completions_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bash_completions_test.go b/bash_completions_test.go index 50fbe09..a626360 100644 --- a/bash_completions_test.go +++ b/bash_completions_test.go @@ -2,6 +2,7 @@ package cobra import ( "bytes" + "io/ioutil" "os" "os/exec" "strings" @@ -174,3 +175,22 @@ func TestBashCompletionDeprecatedFlag(t *testing.T) { t.Errorf("expected completion to not include %q flag: Got %v", flagName, bashCompletion) } } + +func BenchmarkBashCompletion(b *testing.B) { + c := initializeWithRootCmd() + cmdEcho.AddCommand(cmdTimes) + c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated, cmdColon) + + file, err := ioutil.TempFile("", "") + if err != nil { + b.Fatal(err) + } + defer os.Remove(file.Name()) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + if err := c.GenBashCompletion(file); err != nil { + b.Fatal(err) + } + } +}