-
-
Notifications
You must be signed in to change notification settings - Fork 368
/
parameters_test.go
63 lines (57 loc) · 1.4 KB
/
parameters_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
package main
import (
"fmt"
"log"
"path"
"testing"
"github.com/boltdb/bolt"
)
func BenchmarkLoadParameters(b *testing.B) {
var ps FullParameters = *NewFullParameters()
db, err := bolt.Open(path.Join("data", "testdb.db"), 0600, nil)
if err != nil {
Error.Println(err)
}
defer db.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
err = db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
b := tx.Bucket([]byte("resources"))
if b == nil {
return fmt.Errorf("Resources dont exist")
}
v := b.Get([]byte("fullParameters"))
ps = loadParameters(v)
return nil
})
if err != nil {
Error.Println(err)
}
}
}
func BenchmarkGetParameters(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()
b.ResetTimer()
for i := 0; i < b.N; i++ {
getParameters(group, &ps, fingerprintsInMemory, fingerprintsOrdering)
}
}