1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| package rbbench_test
import (
"testing"
"github.com/boltdb/bolt"
redigo "github.com/garyburd/redigo/redis"
redis "github.com/go-redis/redis"
)
var redisOpts = &redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
}
func BenchmarkRedisSet(b *testing.B) {
client := redis.NewClient(redisOpts)
defer client.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
client.Set("key"+string(i), "value", 0).Err()
}
}
func BenchmarkRedisGet(b *testing.B) {
client := redis.NewClient(redisOpts)
defer client.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
client.Get("key" + string(i)).Val()
}
}
func BenchmarkRedigoSet(b *testing.B) {
conn, _ := redigo.Dial("tcp", "localhost:6379")
defer conn.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
conn.Do("SET", "key"+string(i), "value")
}
}
func BenchmarkRedigoGet(b *testing.B) {
conn, _ := redigo.Dial("tcp", "localhost:6379")
defer conn.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
redigo.String(conn.Do("GET", "key"+string(i)))
}
}
func BenchmarkBoltSet(b *testing.B) {
db, _ := bolt.Open("bolt.db", 0600, nil)
defer db.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
db.Update(func(tx *bolt.Tx) error {
b, _ := tx.CreateBucketIfNotExists([]byte("bucket"))
b.Put([]byte("key"+string(i)), []byte("value"))
return nil
})
}
}
func BenchmarkBoltGet(b *testing.B) {
db, _ := bolt.Open("bolt.db", 0600, nil)
defer db.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
db.View(func(tx *bolt.Tx) error {
_ = string(tx.Bucket([]byte("bucket")).Get([]byte("key" + string(i))))
return nil
})
}
}
|