Refactor: extract fn to make map for benchmarks

This commit is contained in:
Bryan Boreham
2017-09-28 08:45:54 +00:00
parent 29f139d424
commit 736ae5e7c8

View File

@@ -126,21 +126,18 @@ func TestLatestMapMerge(t *testing.T) {
}
}
func makeBenchmarkMap(start, finish int, timestamp time.Time) StringLatestMap {
ret := MakeStringLatestMap()
for i := start; i < finish; i++ {
ret = ret.Set(fmt.Sprint(i), timestamp, "1")
}
return ret
}
func BenchmarkLatestMapMerge(b *testing.B) {
var (
left = MakeStringLatestMap()
right = MakeStringLatestMap()
now = time.Now()
)
// two large maps with some overlap
for i := 0; i < 1000; i++ {
left = left.Set(fmt.Sprint(i), now, "1")
}
for i := 700; i < 1700; i++ {
right = right.Set(fmt.Sprint(i), now.Add(1*time.Minute), "1")
}
left := makeBenchmarkMap(0, 1000, time.Now())
right := makeBenchmarkMap(700, 1700, time.Now().Add(1*time.Minute))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {