-
Notifications
You must be signed in to change notification settings - Fork 0
/
priors_test.go
executable file
·108 lines (94 loc) · 2.66 KB
/
priors_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
package main
import (
"log"
"path"
"testing"
"github.com/boltdb/bolt"
"github.com/stretchr/testify/assert"
)
func TestPriorsThreaded(t *testing.T) {
assert.Equal(t, optimizePriorsThreaded("testdb"), nil)
}
// func ExampleTestPriors() {
// // optimizePriors("testdb")
// fmt.Println("OK")
// // Output: OK
// }
//go test -test.bench BenchmarkOptimizePriors -test.benchmem
func BenchmarkOptimizePriors(b *testing.B) {
for i := 0; i < b.N; i++ {
optimizePriors("testdb")
}
}
func BenchmarkOptimizePriorsThreaded(b *testing.B) {
for i := 0; i < b.N; i++ {
optimizePriorsThreaded("testdb")
}
}
func BenchmarkOptimizePriorsThreadedNot(b *testing.B) {
for i := 0; i < b.N; i++ {
optimizePriorsThreadedNot("testdb")
}
}
func BenchmarkCrossValidation(b *testing.B) {
group := "testdb"
// generate the fingerprintsInMemory
fingerprintsInMemory := make(map[string]Fingerprint)
var fingerprintsOrdering []string
db, err := bolt.Open(path.Join(RuntimeArgs.SourcePath, group+".db"), 0600, nil)
if err != nil {
log.Fatal(err)
}
db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("fingerprints"))
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
fingerprintsInMemory[string(k)] = loadFingerprint(v)
fingerprintsOrdering = append(fingerprintsOrdering, string(k))
}
return nil
})
db.Close()
var ps = *NewFullParameters()
getParameters(group, &ps, fingerprintsInMemory, fingerprintsOrdering)
calculatePriors(group, &ps, fingerprintsInMemory, fingerprintsOrdering)
var results = *NewResultsParameters()
for n := range ps.Priors {
ps.Results[n] = results
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for n := range ps.Priors {
ps.Priors[n].Special["MixIn"] = 0.5
ps.Priors[n].Special["VarabilityCutoff"] = 0.005
crossValidation(group, n, &ps, fingerprintsInMemory, fingerprintsOrdering)
break
}
}
}
func BenchmarkCalculatePriors(b *testing.B) {
group := "testdb"
// generate the fingerprintsInMemory
fingerprintsInMemory := make(map[string]Fingerprint)
var fingerprintsOrdering []string
db, err := bolt.Open(path.Join(RuntimeArgs.SourcePath, group+".db"), 0600, nil)
if err != nil {
log.Fatal(err)
}
db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("fingerprints"))
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
fingerprintsInMemory[string(v)] = loadFingerprint(v)
fingerprintsOrdering = append(fingerprintsOrdering, string(v))
}
return nil
})
db.Close()
var ps = *NewFullParameters()
getParameters(group, &ps, fingerprintsInMemory, fingerprintsOrdering)
b.ResetTimer()
for i := 0; i < b.N; i++ {
calculatePriors(group, &ps, fingerprintsInMemory, fingerprintsOrdering)
}
}