Repository navigation
Expand file tree
/
Copy pathcli_bench_test.go
More file actions
78 lines (67 loc) · 1.52 KB
/
Copy pathcli_bench_test.go
File metadata and controls
78 lines (67 loc) · 1.52 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
// SPDX-License-Identifier: EUPL-1.2
// Benchmarks for the CLI surface in cli.go — banner rendering, output
// redirection, formatted printing, and command dispatch. Output is sent
// to Discard so the numbers measure the CLI machinery, not the terminal.
//
// Run: go test -bench='BenchmarkCli' -benchmem -run='^$' .
package core_test
import (
. "dappco.re/go"
)
var (
cliSink Result
cliSinkStr string
)
func BenchmarkCliRegister(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cliSink = CliRegister(New(WithCli()))
}
}
func BenchmarkCli_Print(b *B) {
cli := New(WithCli()).Cli()
cli.SetOutput(Discard)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cli.Print("port=%d", 8080)
}
}
func BenchmarkCli_SetOutput(b *B) {
cli := New(WithCli()).Cli()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cli.SetOutput(Discard)
}
}
func BenchmarkCli_SetBanner(b *B) {
cli := New(WithCli()).Cli()
fn := func(*Cli) string { return "Core" }
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cli.SetBanner(fn)
}
}
func BenchmarkCli_Banner(b *B) {
cli := New(WithCli()).Cli()
cli.SetBanner(func(*Cli) string { return "Core" })
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cliSinkStr = cli.Banner()
}
}
func BenchmarkCli_PrintHelp(b *B) {
cli := New(WithCli()).Cli()
cli.SetOutput(Discard)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cli.PrintHelp()
}
}
func BenchmarkCli_Run(b *B) {
cli := New(WithCli()).Cli()
cli.SetOutput(Discard)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cliSink = cli.Run("status")
}
}