-
Notifications
You must be signed in to change notification settings - Fork 0
/
dict_test.go
46 lines (40 loc) · 979 Bytes
/
dict_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
package adhoctx
import (
"testing"
)
func TestDict(t *testing.T) {
dict := NewDictView()
curr := dict.Reader()
t.Log("curr version", curr)
rw := dict.ReadWriter(curr)
t.Log("tx version", rw)
dict.SetKey(rw, "foo", "bar")
t.Log("expect bar, got", dict.GetKey(rw, "foo"))
committed := dict.Commit(curr, rw)
t.Log("expect true, got", committed)
newState := dict.Reader()
t.Log("new version", newState)
t.Log("expected bar, got", dict.GetKey(newState, "foo"))
t.Log("stats", dict.String())
}
func BenchmarkNormalMaps(b *testing.B) {
m := make(map[string]string)
for i := 0; i < b.N; i++ {
m["hello"] = m["goodbye"]
m["goodbye"] = "forever"
}
b.Log(m)
}
func BenchmarkViewMaps(b *testing.B) {
m := NewDictView()
curr := m.Reader()
rw := m.ReadWriter(curr)
for i := 0; i < b.N; i++ {
m.SetKey(rw, "hello", m.GetKey(rw, "goodbye"))
m.SetKey(rw, "goodbye", "forever")
m.Commit(curr, rw)
curr = rw
rw = m.ReadWriter(curr)
}
b.Log(m.String())
}