/
printer.go
57 lines (48 loc) · 1.31 KB
/
printer.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
package call
import (
"fmt"
"os"
"strconv"
"github.com/olekukonko/tablewriter"
)
// PrintResults output results accord to spec in
// github.com/pedrolopesme/call-it/issues/6
func PrintResults(result Result) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"URL", "STATUS", "TIMES", "AVG", "MIN", "MAX", "TOTAL AVG"})
table.SetAutoFormatHeaders(false)
totalExecution := formatTime(result.totalExecution)
avgExecution := formatTime(result.avgExecution)
minExeuction := formatTime(result.minExecution)
maxExecution := formatTime(result.maxExecution)
firstLine := true
for statusCode, benchmark := range result.status {
statusAvgExecution := formatTime(benchmark.execution / float64(benchmark.total))
if firstLine {
table.Append([]string{
result.URL.String(),
strconv.Itoa(statusCode),
strconv.Itoa(benchmark.total),
statusAvgExecution,
minExeuction,
maxExecution,
avgExecution})
firstLine = false
} else {
table.Append([]string{
"",
strconv.Itoa(statusCode),
strconv.Itoa(benchmark.total),
statusAvgExecution,
" ",
" ",
" "})
}
}
table.SetFooter([]string{"ELAPSED " + totalExecution, "", "", "", "", "", " "})
table.Render()
}
func formatTime(time float64) (output string) {
output = fmt.Sprintf("%.2f", time) + "s"
return
}