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

Function benchmarkRedisGet

bench_test.go:163–188  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
163func 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.

Callers 2

BenchmarkRedisGet_4KiBFunction · 0.85
BenchmarkRedisGet_64KiBFunction · 0.85

Calls 7

benchmarkRedisClientFunction · 0.85
CloseMethod · 0.65
ErrMethod · 0.65
SetMethod · 0.65
NextMethod · 0.65
GetMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected