| 1111 | ) |
| 1112 | |
| 1113 | func BenchmarkParallelCacheGetBatched(b *testing.B) { |
| 1114 | b.ReportAllocs() |
| 1115 | b.StopTimer() |
| 1116 | cache := NewCache(256 * 1024 * 1024) |
| 1117 | buf := make([]byte, 64) |
| 1118 | var key [8]byte |
| 1119 | for i := 0; i < benchDataSize; i++ { |
| 1120 | binary.LittleEndian.PutUint64(key[:], uint64(i)) |
| 1121 | cache.Set(key[:], buf, 0) |
| 1122 | } |
| 1123 | b.StartTimer() |
| 1124 | b.RunParallel(func(pb *testing.PB) { |
| 1125 | keys := make([][]byte, benchBatchSize) |
| 1126 | for i := range keys { |
| 1127 | keys[i] = make([]byte, 8) |
| 1128 | } |
| 1129 | i := 0 |
| 1130 | for pb.Next() { |
| 1131 | for j := 0; j < benchBatchSize; j++ { |
| 1132 | binary.LittleEndian.PutUint64(key[:], uint64((i+j)%benchDataSize)) |
| 1133 | cache.Get(key[:]) |
| 1134 | } |
| 1135 | i++ |
| 1136 | } |
| 1137 | }) |
| 1138 | } |
| 1139 | |
| 1140 | func BenchmarkParallelCacheMultiGetBatched(b *testing.B) { |
| 1141 | b.ReportAllocs() |