-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_bench_test.go
More file actions
62 lines (53 loc) · 1.43 KB
/
Copy pathcommand_bench_test.go
File metadata and controls
62 lines (53 loc) · 1.43 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
// SPDX-License-Identifier: EUPL-1.2
// Benchmarks for the command tree in command.go — i18n-key derivation,
// action dispatch, managed-lifecycle check, and registration on Core.
//
// Run: go test -bench='BenchmarkCommand|BenchmarkCore_Command' -benchmem -run='^$' .
package core_test
import (
. "dappco.re/go"
)
var (
cmdSinkStr string
cmdSinkResult Result
cmdSinkBool bool
cmdSinkSlice []string
)
func BenchmarkCommand_I18nKey(b *B) {
cmd := &Command{Path: "deploy/to/homelab"}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cmdSinkStr = cmd.I18nKey()
}
}
func BenchmarkCommand_Run(b *B) {
cmd := &Command{Action: func(Options) Result { return Result{OK: true} }}
opts := NewOptions()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cmdSinkResult = cmd.Run(opts)
}
}
func BenchmarkCommand_IsManaged(b *B) {
cmd := &Command{Managed: "process.daemon"}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cmdSinkBool = cmd.IsManaged()
}
}
func BenchmarkCore_Command(b *B) {
c := New()
cmd := Command{Name: "deploy", Path: "deploy", Action: func(Options) Result { return Result{OK: true} }}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cmdSinkResult = c.Command("deploy", cmd)
}
}
func BenchmarkCore_Commands(b *B) {
c := New()
c.Command("deploy", Command{Name: "deploy", Path: "deploy", Action: func(Options) Result { return Result{OK: true} }})
b.ReportAllocs()
for i := 0; i < b.N; i++ {
cmdSinkSlice = c.Commands()
}
}