-
Notifications
You must be signed in to change notification settings - Fork 4
/
benchmark_test.go
71 lines (57 loc) · 1023 Bytes
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package PaxiBFT
import (
"sync"
"testing"
"github.com/salemmohammed/PaxiBFT/log"
)
type FakeDB struct {
start int
end int
local int
total int
lock sync.Mutex
}
func (f *FakeDB) Init() error {
return nil
}
func (f *FakeDB) Stop() error {
log.Infof("local / total = %d / %d = %f", f.local, f.total, float64(f.local)/float64(f.total))
return nil
}
func (f *FakeDB) Read(key int) (int, error) {
//log.Debugf("Read %d", key)
f.lock.Lock()
f.total++
if key >= f.start && key <= f.end {
f.local++
}
f.lock.Unlock()
return 0, nil
}
func (f *FakeDB) Write(key, value int) error {
//log.Debugf("Write %d", key)
f.lock.Lock()
f.total++
if key >= f.start && key <= f.end {
f.local++
}
f.lock.Unlock()
return nil
}
func TestBenchmark(t *testing.T) {
start := 200
end := 400
f := new(FakeDB)
f.start = start
f.end = end
b := NewBenchmark(f)
b.Min = start
b.K = 1000
b.Distribution = "normal"
b.Mu = 300
b.Sigma = 50
b.T = 0
b.N = 10000
b.LinearizabilityCheck = false
b.Run()
}