-
Notifications
You must be signed in to change notification settings - Fork 1
/
recoder.go
52 lines (43 loc) · 1011 Bytes
/
recoder.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
package main
import (
"fmt"
"strconv"
"time"
)
type Result struct {
Status int
Duration float64
}
type DurCount struct {
Duration float64
Count int
}
var result = make(map[string][]Result)
func ShowResult() {
for _, r := range scenario.Requests {
m := result[r.Title]
rm := map[int]DurCount{}
for _, res := range m {
c := rm[res.Status].Count
d := rm[res.Status].Duration
dc := DurCount{Duration: d + res.Duration, Count: c + 1}
rm[res.Status] = dc
}
fmt.Println(r.Title)
for st, dc := range rm {
status := strconv.Itoa(st)
req := strconv.Itoa(dc.Count) + " req"
tpr := strconv.FormatFloat(dc.Duration*1000/float64(dc.Count), 'f', 2, 64) + " ms/req"
fmt.Println("\t" + status + ": " + req + ", " + tpr + "\n")
}
}
}
func CreateReport() {
// ToDo
fmt.Println("Report will be created.")
}
func Record(title string, status int, t time.Duration) {
d := t.Seconds()
r := Result{Status: status, Duration: d}
result[title] = append(result[title], r)
}