MCPcopy
hub / github.com/redis/go-redis / benchmarkRedisSetGetBuffer

Function benchmarkRedisSetGetBuffer

bench_test.go:222–248  ·  view source on GitHub ↗

benchmarkRedisSetGetBuffer round-trips a payload through SetFromBuffer and GetToBuffer, exercising both zero-copy paths on a shared buffer.

(b *testing.B, size int)

Source from the content-addressed store, hash-verified

220// benchmarkRedisSetGetBuffer round-trips a payload through SetFromBuffer
221// and GetToBuffer, exercising both zero-copy paths on a shared buffer.
222func 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.

Calls 7

benchmarkRedisClientFunction · 0.85
CloseMethod · 0.65
NextMethod · 0.65
ErrMethod · 0.65
SetFromBufferMethod · 0.65
ResultMethod · 0.65
GetToBufferMethod · 0.65

Tested by

no test coverage detected