github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/names/handle_show_test.go (about) 1 package namesPkg 2 3 import ( 4 "bufio" 5 "bytes" 6 "testing" 7 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" 10 ) 11 12 func BenchmarkNamesOptions_HandleShow_CommandLine(b *testing.B) { 13 b.StopTimer() 14 buf := bytes.NewBuffer([]byte{}) 15 w := bufio.NewWriter(buf) 16 17 opts := defaultNamesOptions 18 opts.Globals.Format = "txt" 19 opts.Globals.Writer = w 20 21 b.StartTimer() 22 // Emptying in-memory cache simulates calling this code multiple times 23 // on the command line 24 names.ClearCache() 25 rCtx := output.NewRenderContext() 26 err := opts.HandleShow(rCtx) 27 if err != nil { 28 b.Fatal(err) 29 } 30 } 31 32 func BenchmarkNamesOptions_HandleShow_Api(b *testing.B) { 33 b.StopTimer() 34 buf := bytes.NewBuffer([]byte{}) 35 w := bufio.NewWriter(buf) 36 37 opts := defaultNamesOptions 38 opts.Globals.Format = "txt" 39 opts.Globals.Writer = w 40 41 b.StartTimer() 42 // Note: we are not calling names.ClearCache() here 43 rCtx := output.NewRenderContext() 44 err := opts.HandleShow(rCtx) 45 if err != nil { 46 b.Fatal(err) 47 } 48 }