benchmarkRedisSetGetBuffer round-trips a payload through SetFromBuffer and GetToBuffer, exercising both zero-copy paths on a shared buffer.
(b *testing.B, size int)
| 220 | // benchmarkRedisSetGetBuffer round-trips a payload through SetFromBuffer |
| 221 | // and GetToBuffer, exercising both zero-copy paths on a shared buffer. |
| 222 | func benchmarkRedisSetGetBuffer(b *testing.B, size int) { |
| 223 | ctx := context.Background() |
| 224 | client := benchmarkRedisClient(ctx, 10) |
| 225 | defer client.Close() |
| 226 | |
| 227 | value := bytes.Repeat([]byte{'x'}, size) |
| 228 | |
| 229 | b.SetBytes(int64(size)) |
| 230 | b.ReportAllocs() |
| 231 | b.ResetTimer() |
| 232 | |
| 233 | b.RunParallel(func(pb *testing.PB) { |
| 234 | buf := make([]byte, size) |
| 235 | for pb.Next() { |
| 236 | if err := client.SetFromBuffer(ctx, "key", value).Err(); err != nil { |
| 237 | b.Fatal(err) |
| 238 | } |
| 239 | n, err := client.GetToBuffer(ctx, "key", buf).Result() |
| 240 | if err != nil { |
| 241 | b.Fatal(err) |
| 242 | } |
| 243 | if n != size { |
| 244 | b.Fatalf("n = %d, want %d", n, size) |
| 245 | } |
| 246 | } |
| 247 | }) |
| 248 | } |
| 249 | |
| 250 | // benchmarkRedisSet runs Set with a []byte value, the closest existing |
| 251 | // peer of SetFromBuffer for direct comparison. |
no test coverage detected