-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathindex_test.go
More file actions
83 lines (74 loc) · 2.19 KB
/
Copy pathindex_test.go
File metadata and controls
83 lines (74 loc) · 2.19 KB
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
package vecmt
import (
"testing"
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/dag"
"github.com/Fantom-foundation/lachesis-base/inter/dag/tdag"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/kvdb/memorydb"
"github.com/Fantom-foundation/go-opera/inter"
)
var (
testASCIIScheme = `
a1.0 b1.0 c1.0 d1.0 e1.0
║ ║ ║ ║ ║
║ ╠──────╫───── d2.0 ║
║ ║ ║ ║ ║
║ b2.1 ──╫──────╣ e2.1
║ ║ ║ ║ ║
║ ╠──────╫───── d3.1 ║
a2.1 ──╣ ║ ║ ║
║ ║ ║ ║ ║
║ b3.2 ──╣ ║ ║
║ ║ ║ ║ ║
║ ╠──────╫───── d4.2 ║
║ ║ ║ ║ ║
║ ╠───── c2.2 ║ e3.2
║ ║ ║ ║ ║
`
)
type eventWithCreationTime struct {
dag.Event
creationTime inter.Timestamp
}
func (e *eventWithCreationTime) CreationTime() inter.Timestamp {
return e.creationTime
}
func BenchmarkIndex_Add(b *testing.B) {
b.StopTimer()
ordered := make(dag.Events, 0)
nodes, _, _ := tdag.ASCIIschemeForEach(testASCIIScheme, tdag.ForEachEvent{
Process: func(e dag.Event, name string) {
ordered = append(ordered, e)
},
})
validatorsBuilder := pos.NewBuilder()
for _, peer := range nodes {
validatorsBuilder.Set(peer, 1)
}
validators := validatorsBuilder.Build()
events := make(map[hash.Event]dag.Event)
getEvent := func(id hash.Event) dag.Event {
return events[id]
}
for _, e := range ordered {
events[e.ID()] = e
}
vecClock := NewIndex(func(err error) { panic(err) }, LiteConfig())
vecClock.Reset(validators, memorydb.New(), getEvent)
for i := 0; i < b.N; i++ {
b.StopTimer()
vecClock.Reset(validators, memorydb.New(), getEvent)
b.StartTimer()
for _, e := range ordered {
err := vecClock.Add(&eventWithCreationTime{e, inter.Timestamp(e.Seq())})
if err != nil {
panic(err)
}
i++
if i >= b.N {
break
}
}
}
}