-
Notifications
You must be signed in to change notification settings - Fork 127
/
bench_test.go
99 lines (81 loc) · 1.74 KB
/
bench_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
package sphinx
import (
"bytes"
"testing"
"github.com/btcsuite/btcd/btcec/v2"
)
var (
s *OnionPacket
p *ProcessedPacket
)
func BenchmarkPathPacketConstruction(b *testing.B) {
b.StopTimer()
var (
err error
sphinxPacket *OnionPacket
route PaymentPath
)
for i := 0; i < 20; i++ {
privKey, err := btcec.NewPrivateKey()
if err != nil {
b.Fatalf("unable to generate key: %v", privKey)
}
hopData := HopData{
ForwardAmount: uint64(i),
OutgoingCltv: uint32(i),
}
copy(hopData.NextAddress[:], bytes.Repeat([]byte{byte(i)}, 8))
hopPayload, err := NewLegacyHopPayload(&hopData)
if err != nil {
b.Fatalf("unable to create new hop payload: %v", err)
}
route[i] = OnionHop{
NodePub: *privKey.PubKey(),
HopPayload: hopPayload,
}
}
d, _ := btcec.PrivKeyFromBytes(bytes.Repeat([]byte{'A'}, 32))
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
sphinxPacket, err = NewOnionPacket(
&route, d, nil, BlankPacketFiller,
)
if err != nil {
b.Fatalf("unable to create packet: %v", err)
}
}
s = sphinxPacket
}
func BenchmarkProcessPacket(b *testing.B) {
b.StopTimer()
path, _, _, sphinxPacket, err := newTestRoute(1)
if err != nil {
b.Fatalf("unable to create test route: %v", err)
}
b.ReportAllocs()
path[0].log.Start()
defer path[0].log.Stop()
b.StartTimer()
var (
pkt *ProcessedPacket
)
for i := 0; i < b.N; i++ {
pkt, err = path[0].ProcessOnionPacket(
sphinxPacket, nil, uint32(i),
)
if err != nil {
b.Fatalf("unable to process packet %d: %v", i, err)
}
b.StopTimer()
router := path[0]
router.log.Stop()
path[0] = &Router{
onionKey: router.onionKey,
log: NewMemoryReplayLog(),
}
path[0].log.Start()
b.StartTimer()
}
p = pkt
}