-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathbench_test.go
85 lines (68 loc) · 1.39 KB
/
bench_test.go
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
83
84
85
package sharding_test
import (
"math/rand"
"testing"
"time"
"github.com/go-pg/sharding/v8"
"github.com/go-pg/pg/v10"
)
func benchmarkDB() *pg.DB {
return pg.Connect(&pg.Options{
User: "postgres",
Database: "postgres",
DialTimeout: 30 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
PoolSize: 10,
PoolTimeout: 30 * time.Second,
})
}
func BenchmarkGopg(b *testing.B) {
db := benchmarkDB()
defer db.Close()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := db.Exec("SELECT 1")
if err != nil {
b.Fatal(err)
}
}
})
}
func BenchmarkCluster(b *testing.B) {
db := benchmarkDB()
defer db.Close()
cluster := sharding.NewCluster([]*pg.DB{db}, 1)
defer cluster.Close()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := cluster.Shard(0).Exec("SELECT 1")
if err != nil {
b.Fatal(err)
}
}
})
}
var sink *sharding.SubCluster
func BenchmarkSubCluster(b *testing.B) {
db := benchmarkDB()
defer db.Close()
cluster := sharding.NewCluster([]*pg.DB{db}, 1)
defer cluster.Close()
b.RunParallel(func(pb *testing.PB) {
n := rand.Int63()
for pb.Next() {
sink = cluster.SubCluster(n, 32)
}
})
}
func BenchmarkNewUUID(b *testing.B) {
tm := time.Now()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = sharding.NewUUID(0, tm)
}
})
}