forked from schwartzmx/gremtune
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gremcos_benchmark_test.go
53 lines (40 loc) · 1.46 KB
/
gremcos_benchmark_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
package gremcos
import (
"sync"
"testing"
"github.com/supplyon/gremcos/interfaces"
)
var benchmarkClient interfaces.QueryExecutor
var benchmarkPool *pool
var once sync.Once
func initBeforeBenchmark() {
t := &testing.T{}
t.Log("Starting the benchmark. In order to run it a local gremlin server has to run and listen on 8182")
// create the error channels
clientErrChannel := make(chan error)
poolErrChannel := make(chan error)
// create failing readers for those channels
go failingErrorChannelConsumerFunc(clientErrChannel, t)
go failingErrorChannelConsumerFunc(poolErrChannel, t)
benchmarkClient = newTestClient(t, clientErrChannel)
benchmarkPool = newTestPool(t, poolErrChannel)
seedData(t, benchmarkClient)
}
func benchmarkPoolExecute(i int, b *testing.B) {
once.Do(initBeforeBenchmark)
for n := 0; n < i; n++ {
go func(p *pool) {
_, err := p.Execute(`g.V('1234').label()`)
if err != nil {
b.Error(err)
}
}(benchmarkPool)
}
}
func BenchmarkPoolExecute1(b *testing.B) { benchmarkPoolExecute(1, b) }
func BenchmarkPoolExecute5(b *testing.B) { benchmarkPoolExecute(5, b) }
func BenchmarkPoolExecute10(b *testing.B) { benchmarkPoolExecute(10, b) }
func BenchmarkPoolExecute20(b *testing.B) { benchmarkPoolExecute(20, b) }
func BenchmarkPoolExecute40(b *testing.B) { benchmarkPoolExecute(40, b) }
func BenchmarkPoolExecute80(b *testing.B) { benchmarkPoolExecute(80, b) }
func BenchmarkPoolExecute160(b *testing.B) { benchmarkPoolExecute(160, b) }