| 1029 | } |
| 1030 | |
| 1031 | func BenchmarkParallelCacheGet(b *testing.B) { |
| 1032 | b.ReportAllocs() |
| 1033 | b.StopTimer() |
| 1034 | cache := NewCache(256 * 1024 * 1024) |
| 1035 | buf := make([]byte, 64) |
| 1036 | var key [8]byte |
| 1037 | for i := 0; i < b.N; i++ { |
| 1038 | binary.LittleEndian.PutUint64(key[:], uint64(i)) |
| 1039 | cache.Set(key[:], buf, 0) |
| 1040 | } |
| 1041 | b.StartTimer() |
| 1042 | b.RunParallel(func(pb *testing.PB) { |
| 1043 | counter := 0 |
| 1044 | b.ReportAllocs() |
| 1045 | for pb.Next() { |
| 1046 | binary.LittleEndian.PutUint64(key[:], uint64(counter)) |
| 1047 | cache.Get(key[:]) |
| 1048 | counter = counter + 1 |
| 1049 | } |
| 1050 | }) |
| 1051 | } |
| 1052 | |
| 1053 | func BenchmarkCacheGetWithBuf(b *testing.B) { |
| 1054 | b.ReportAllocs() |