benchmarkRedisGet runs the classic Get-into-string path so it can be compared head-to-head with benchmarkRedisGetToBuffer for the same value size. The key is populated once up front and read in a parallel loop.
(b *testing.B, size int)
| 161 | // compared head-to-head with benchmarkRedisGetToBuffer for the same value |
| 162 | // size. The key is populated once up front and read in a parallel loop. |
| 163 | func benchmarkRedisGet(b *testing.B, size int) { |
| 164 | ctx := context.Background() |
| 165 | client := benchmarkRedisClient(ctx, 10) |
| 166 | defer client.Close() |
| 167 | |
| 168 | value := bytes.Repeat([]byte{'x'}, size) |
| 169 | if err := client.Set(ctx, "key", value, 0).Err(); err != nil { |
| 170 | b.Fatal(err) |
| 171 | } |
| 172 | |
| 173 | b.SetBytes(int64(size)) |
| 174 | b.ReportAllocs() |
| 175 | b.ResetTimer() |
| 176 | |
| 177 | b.RunParallel(func(pb *testing.PB) { |
| 178 | for pb.Next() { |
| 179 | got, err := client.Get(ctx, "key").Bytes() |
| 180 | if err != nil { |
| 181 | b.Fatal(err) |
| 182 | } |
| 183 | if len(got) != size { |
| 184 | b.Fatalf("got len %d, want %d", len(got), size) |
| 185 | } |
| 186 | } |
| 187 | }) |
| 188 | } |
| 189 | |
| 190 | // benchmarkRedisGetToBuffer reads the value into a per-goroutine reusable |
| 191 | // buffer via GetToBuffer, exercising the zero-copy receive path. |