forked from mirror/redis
More benchmarks.
This commit is contained in:
parent
42ce58ed85
commit
00a131e3a9
|
@ -132,17 +132,16 @@ func parseReply(rd *bufio.Reader, p multiBulkParser) (interface{}, error) {
|
|||
return nil, Nil
|
||||
}
|
||||
|
||||
replyLenInt32, err := strconv.ParseInt(string(line[1:]), 10, 32)
|
||||
replyLen, err := strconv.Atoi(string(line[1:]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
replyLen := int(replyLenInt32) + 2
|
||||
|
||||
line, err = readN(rd, replyLen)
|
||||
b, err := readN(rd, replyLen+2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return string(line[:len(line)-2]), nil
|
||||
return string(b[:replyLen]), nil
|
||||
case '*':
|
||||
if len(line) == 3 && line[1] == '-' && line[2] == '1' {
|
||||
return nil, Nil
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package redis
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gopkg.in/bufio.v1"
|
||||
)
|
||||
|
||||
func BenchmarkParseReplyStatus(b *testing.B) {
|
||||
benchmarkParseReply(b, "+OK\r\n", nil, false)
|
||||
}
|
||||
|
||||
func BenchmarkParseReplyInt(b *testing.B) {
|
||||
benchmarkParseReply(b, ":1\r\n", nil, false)
|
||||
}
|
||||
|
||||
func BenchmarkParseReplyError(b *testing.B) {
|
||||
benchmarkParseReply(b, "-Error message\r\n", nil, true)
|
||||
}
|
||||
|
||||
func BenchmarkParseReplyString(b *testing.B) {
|
||||
benchmarkParseReply(b, "$5\r\nhello\r\n", nil, false)
|
||||
}
|
||||
|
||||
func BenchmarkParseReplySlice(b *testing.B) {
|
||||
benchmarkParseReply(b, "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", parseSlice, false)
|
||||
}
|
||||
|
||||
func benchmarkParseReply(b *testing.B, reply string, p multiBulkParser, wanterr bool) {
|
||||
b.StopTimer()
|
||||
|
||||
buf := &bufio.Buffer{}
|
||||
rd := bufio.NewReader(buf)
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf.WriteString(reply)
|
||||
}
|
||||
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := parseReply(rd, p)
|
||||
if !wanterr && err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAppendArgs(b *testing.B) {
|
||||
buf := make([]byte, 0, 64)
|
||||
args := []string{"hello", "world", "foo", "bar"}
|
||||
for i := 0; i < b.N; i++ {
|
||||
appendArgs(buf, args)
|
||||
}
|
||||
}
|
|
@ -73,8 +73,7 @@ func (c *Pipeline) Exec() ([]Cmder, error) {
|
|||
}
|
||||
|
||||
func (c *Pipeline) execCmds(cn *conn, cmds []Cmder) error {
|
||||
err := c.writeCmd(cn, cmds...)
|
||||
if err != nil {
|
||||
if err := c.writeCmd(cn, cmds...); err != nil {
|
||||
setCmdsErr(cmds, err)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -3138,3 +3138,27 @@ func (t *RedisTest) BenchmarkRedisMGet(c *C) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *RedisTest) BenchmarkSetExpire(c *C) {
|
||||
for i := 0; i < c.N; i++ {
|
||||
if err := t.client.Set("key", "hello").Err(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := t.client.Expire("key", time.Second).Err(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *RedisTest) BenchmarkPipeline(c *C) {
|
||||
for i := 0; i < c.N; i++ {
|
||||
_, err := t.client.Pipelined(func(pipe *redis.Pipeline) error {
|
||||
pipe.Set("key", "hello")
|
||||
pipe.Expire("key", time.Second)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue