-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (84 loc) · 1.88 KB
/
main.go
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
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"ferbench/cpu"
"ferbench/tui"
"github.com/urfave/cli/v2"
"log"
"os"
"runtime"
)
func main() {
runLength := 30.0
numThreads := runtime.NumCPU()
mt := false
st := false
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Version number",
}
app := &cli.App{
Name: "ferbench",
Usage: "A simple commandline benchmark, with no flags runs both a single thread and multi thread benchmark",
Version: "v0.11",
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "singlethread",
Aliases: []string{"st"},
Usage: "Runs a single thread cpu benchmark only",
Destination: &st,
},
&cli.BoolFlag{
Name: "multithread",
Aliases: []string{"mt"},
Usage: "Runs a multi thread cpu benchmark only",
Destination: &mt,
},
&cli.Float64Flag{
Name: "length",
Value: 30,
Usage: "Sets how long to run each benchmarks for",
Destination: &runLength,
Aliases: []string{"l"},
},
&cli.IntFlag{
Name: "threads",
Value: runtime.NumCPU(),
Usage: "Sets the number of threads to use for multithread benchmark",
Destination: &numThreads,
Aliases: []string{"t"},
},
},
Action: func(ctx *cli.Context) error {
all := !st && !mt
if st || all {
err := cpu.Bench(runLength, 1)
if err != nil {
return err
}
}
if mt || all {
err := cpu.Bench(runLength, numThreads)
return err
}
return nil
},
Before: func(ctx *cli.Context) error {
tui.ShowMainHeader()
err := tui.ShowOSInfo()
if err != nil {
return err
}
err = tui.ShowCPUInfo()
if err != nil {
return err
}
return nil
},
}
app.Suggest = true
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}