-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
32 lines (29 loc) · 998 Bytes
/
output.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
package client
import (
"fmt"
"os"
)
func WriteOutputToFile(outputFilePath string, responseCount []ResponseStatus) error {
file, err := os.Create(outputFilePath)
if err != nil {
return err
}
defer file.Close()
sum := 0.0
experimentAverageLatency := 0.0
for _, count := range responseCount {
throughput := float64(count.readOperations + count.writeOperations)
averageLatency := 0.0
for _, latency := range count.latencies {
averageLatency += float64(latency.Milliseconds())
}
averageLatency = averageLatency / float64(len(count.latencies))
sum += throughput
experimentAverageLatency += averageLatency
file.WriteString(fmt.Sprintf("Throughput: %f\n", throughput))
file.WriteString(fmt.Sprintf("Average Latency: %f\n", averageLatency))
}
file.WriteString(fmt.Sprintf("Average Throughput: %f\n", sum/float64(len(responseCount))))
file.WriteString(fmt.Sprintf("Experiment Average Latency: %f\n", experimentAverageLatency/float64(len(responseCount))))
return nil
}