-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark_result.go
More file actions
53 lines (38 loc) · 1.42 KB
/
benchmark_result.go
File metadata and controls
53 lines (38 loc) · 1.42 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
46
47
48
49
50
51
52
53
package main
import "time"
type BenchmarkResult struct {
getCount int
missCount int
setCount int
StatisticBuckets []BenchmarkStatistic
}
func (benchmarkResult *BenchmarkResult) addStatistic(index int, benchmarkStatistic BenchmarkStatistic) {
if index > len(benchmarkResult.StatisticBuckets)-1 {
newStatisticBuckets := make([]BenchmarkStatistic, index+1)
copy(newStatisticBuckets, benchmarkResult.StatisticBuckets)
benchmarkResult.StatisticBuckets = newStatisticBuckets
}
statisticBucket := benchmarkResult.StatisticBuckets[index]
statisticBucket.operationCount += benchmarkStatistic.operationCount
statisticBucket.duration += benchmarkStatistic.duration
benchmarkResult.StatisticBuckets[index] = statisticBucket
}
func (benchmarkResult *BenchmarkResult) addDuration(duration time.Duration, typeName string) {
index := int(duration / time.Millisecond)
benchmarkResult.addStatistic(index, BenchmarkStatistic{1, duration})
if typeName == "get" {
benchmarkResult.getCount++
} else if typeName == "set" {
benchmarkResult.setCount++
} else {
benchmarkResult.missCount++
}
}
func (benchmarkResult *BenchmarkResult) addResult(source *BenchmarkResult) {
for index, benchmarkStatistic := range source.StatisticBuckets {
benchmarkResult.addStatistic(index, benchmarkStatistic)
}
benchmarkResult.getCount += source.getCount
benchmarkResult.missCount += source.missCount
benchmarkResult.setCount += source.setCount
}