forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobability_estimator_test.go
95 lines (86 loc) · 2.26 KB
/
probability_estimator_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
package routing
import (
"math"
"testing"
"time"
"github.com/lightningnetwork/lnd/routing/route"
)
// Create a set of test results.
var resultTime = time.Unix(1674169200, 0) // 20.01.2023
var now = time.Unix(1674190800, 0) // 6 hours later
var results = NodeResults{
route.Vertex{byte(0)}: TimedPairResult{
FailAmt: 200_000_000,
FailTime: resultTime,
SuccessAmt: 100_000_000,
SuccessTime: resultTime,
},
route.Vertex{byte(1)}: TimedPairResult{
FailAmt: 200_000_000,
FailTime: resultTime,
SuccessAmt: 100_000_000,
SuccessTime: resultTime,
},
route.Vertex{byte(2)}: TimedPairResult{
FailAmt: 200_000_000,
FailTime: resultTime,
SuccessAmt: 100_000_000,
SuccessTime: resultTime,
},
route.Vertex{byte(3)}: TimedPairResult{
FailAmt: 200_000_000,
FailTime: resultTime,
SuccessAmt: 100_000_000,
SuccessTime: resultTime,
},
route.Vertex{byte(4)}: TimedPairResult{
FailAmt: 200_000_000,
FailTime: resultTime,
SuccessAmt: 100_000_000,
SuccessTime: resultTime,
},
}
// probability is a package level variable to prevent the compiler from
// optimizing the benchmark.
var probability float64
// BenchmarkBimodalPairProbability benchmarks the probability calculation.
func BenchmarkBimodalPairProbability(b *testing.B) {
estimator := BimodalEstimator{
BimodalConfig: BimodalConfig{
BimodalScaleMsat: scale,
BimodalNodeWeight: 0.2,
BimodalDecayTime: 48 * time.Hour,
},
}
toNode := route.Vertex{byte(0)}
var p float64
for i := 0; i < b.N; i++ {
p = estimator.PairProbability(now, results, toNode,
150_000_000, 300_000)
}
probability = p
}
// BenchmarkAprioriPairProbability benchmarks the probability calculation.
func BenchmarkAprioriPairProbability(b *testing.B) {
estimator := AprioriEstimator{
AprioriConfig: AprioriConfig{
AprioriWeight: 0.2,
PenaltyHalfLife: 48 * time.Hour,
AprioriHopProbability: 0.5,
},
}
toNode := route.Vertex{byte(0)}
var p float64
for i := 0; i < b.N; i++ {
p = estimator.PairProbability(now, results, toNode,
150_000_000, 300_000)
}
probability = p
}
// BenchmarkExp benchmarks the exponential function as provided by the math
// library.
func BenchmarkExp(b *testing.B) {
for i := 0; i < b.N; i++ {
math.Exp(0.1)
}
}