-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (36 loc) · 1.13 KB
/
main.go
File metadata and controls
45 lines (36 loc) · 1.13 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
package main
import (
"flag"
"fmt"
"log"
"strings"
)
var timeToWait = flag.Int("wait-time", 3000, "the number of milliseconds to wait until the program is assumed to be interactive")
var numTimes = flag.Int64("n", 5, "the number of runs to time a command before computing the average")
var printExpected = flag.Bool("print-expected", false, "whether to print what the time will consider the interactive state of the program")
func main() {
flag.Parse()
cmd, err := parseCommand(strings.Join(flag.Args(), " "))
if err != nil {
fmt.Println("Invalid command")
log.Fatal(err)
}
fmt.Println("Finding expected output...")
fmt.Printf("Program is assumed to be interactive after %d milliseconds\n", *timeToWait)
fmt.Println()
expectedOutput, err := findExpected(cmd)
if err != nil {
log.Fatal(err)
}
if *printExpected {
fmt.Println("Expected output:")
fmt.Println(string(expectedOutput))
fmt.Println()
}
fmt.Println("Timing command...")
duration, err := timeCommandAverage(cmd, expectedOutput, *numTimes)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Time to interactive: %d milliseconds\n", duration.Milliseconds())
}