1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

fix: update some argument counts in pre-allocs

In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
This commit is contained in:
ffenix113
2021-11-05 18:46:21 +01:00
parent 47ac23e055
commit f6974ebb5c
2 changed files with 44 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"strconv"
"strings"
"sync"
"testing"
@ -233,6 +234,45 @@ func BenchmarkZAdd(b *testing.B) {
})
}
func BenchmarkXRead(b *testing.B) {
ctx := context.Background()
client := benchmarkRedisClient(ctx, 10)
defer client.Close()
args := redis.XAddArgs{
Stream: "1",
ID: "*",
Values: map[string]string{"uno": "dos"},
}
lenStreams := 16
streams := make([]string, 0, lenStreams)
for i := 0; i < lenStreams; i++ {
streams = append(streams, strconv.Itoa(i))
}
for i := 0; i < lenStreams; i++ {
streams = append(streams, "0")
}
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
client.XAdd(ctx, &args)
err := client.XRead(ctx, &redis.XReadArgs{
Streams: streams,
Count: 1,
Block: time.Second,
}).Err()
if err != nil {
b.Fatal(err)
}
}
})
}
var clientSink *redis.Client
func BenchmarkWithContext(b *testing.B) {