forked from freeeve/cq
-
Notifications
You must be signed in to change notification settings - Fork 11
/
driver_bench_test.go
172 lines (138 loc) · 3.48 KB
/
driver_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package cq
import (
"fmt"
"log"
"time"
. "gopkg.in/check.v1"
)
type BenchmarkSuite struct{}
var _ = Suite(&BenchmarkSuite{})
func (s *BenchmarkSuite) SetUpTest(c *C) {
db := testConn()
_, err := db.Exec("start n=node(*) where has(n.`benchmark~test~id`) delete n")
if err != nil {
log.Println(err)
}
_, err = db.Exec("create constraint on (t:Test) assert t.`benchmark~test~id` is unique")
if err != nil {
log.Println(err)
}
}
func (s *BenchmarkSuite) TearDownTest(c *C) {
db := testConn()
_, err := db.Exec("start n=node(*) where has(n.`benchmark~test~id`) delete n")
if err != nil {
log.Println(err)
}
_, err = db.Exec("drop constraint on (t:Test) assert t.`benchmark~test~id` is unique")
if err != nil {
log.Println(err)
}
}
func (s *BenchmarkSuite) BenchmarkSimpleQuery(c *C) {
stmt := prepareTest("return 1")
defer stmt.Close()
var test int
for i := 0; i < c.N; i++ {
rows, err := stmt.Query()
c.Assert(err, IsNil)
rows.Scan(&test)
rows.Close()
}
}
func (s *BenchmarkSuite) BenchmarkSimpleCreate(c *C) {
stmt := prepareTest("create ({`benchmark~test~id`:{0}, timestamp:{1}})")
defer stmt.Close()
var test int
for i := 0; i < c.N; i++ {
rows, err := stmt.Query(i, fmt.Sprint(time.Now().UnixNano()))
c.Assert(err, IsNil)
rows.Scan(&test)
rows.Close()
}
}
func (s *BenchmarkSuite) BenchmarkSimpleCreateLabel(c *C) {
stmt := prepareTest("create (:Test {`benchmark~test~id`:{0}, timestamp:{1}})")
defer stmt.Close()
var test int
for i := 0; i < c.N; i++ {
rows, err := stmt.Query(i, fmt.Sprint(time.Now().UnixNano()))
c.Assert(err, IsNil)
rows.Scan(&test)
rows.Close()
}
}
func (s *BenchmarkSuite) BenchmarkTx10SimpleCreate(c *C) {
txSizeSimpleCreate(c, 10)
}
func (s *BenchmarkSuite) BenchmarkTx100SimpleCreate(c *C) {
txSizeSimpleCreate(c, 100)
}
func (s *BenchmarkSuite) BenchmarkTx1000SimpleCreate(c *C) {
txSizeSimpleCreate(c, 1000)
}
func (s *BenchmarkSuite) BenchmarkTx10000SimpleCreate(c *C) {
txSizeSimpleCreate(c, 10000)
}
func txSizeSimpleCreate(c *C, size int) {
conn := testConn()
defer conn.Close()
tx, err := conn.Begin()
if err != nil {
log.Fatal(err)
}
stmt, err := tx.Prepare("create ({`benchmark~test~id`:{0}})")
c.Assert(err, IsNil)
for i := 0; i < c.N; i++ {
_, err = stmt.Exec(i)
c.Assert(err, IsNil)
if (i > 0 && i%size == 0) || i == c.N-1 {
err = tx.Commit()
c.Assert(err, IsNil)
if i < c.N-1 {
tx, err = conn.Begin()
c.Assert(err, IsNil)
stmt.Close()
stmt, err = tx.Prepare("create ({`benchmark~test~id`:{0}})")
c.Assert(err, IsNil)
}
}
}
}
func (s *BenchmarkSuite) BenchmarkTx10SimpleMerge(c *C) {
txSizeSimpleMerge(c, 10)
}
func (s *BenchmarkSuite) BenchmarkTx100SimpleMerge(c *C) {
txSizeSimpleMerge(c, 100)
}
func (s *BenchmarkSuite) BenchmarkTx1000SimpleMerge(c *C) {
txSizeSimpleMerge(c, 1000)
}
func (s *BenchmarkSuite) BenchmarkTx10000SimpleMerge(c *C) {
txSizeSimpleMerge(c, 10000)
}
func txSizeSimpleMerge(c *C, size int) {
conn := testConn()
defer conn.Close()
tx, err := conn.Begin()
if err != nil {
log.Fatal(err)
}
stmt, err := tx.Prepare("merge (:Test {`benchmark~test~id`:{0}})")
c.Assert(err, IsNil)
for i := 0; i < c.N; i++ {
_, err = stmt.Exec(i)
c.Assert(err, IsNil)
if (i > 0 && i%size == 0) || i == c.N-1 {
err = tx.Commit()
c.Assert(err, IsNil)
if i < c.N-1 {
tx, err = conn.Begin()
c.Assert(err, IsNil)
stmt.Close()
stmt, err = tx.Prepare("merge (:Test {`benchmark~test~id`:{0}})")
c.Assert(err, IsNil)
}
}
}
}