graphdb: add benchmark for isPublicNode query
In this commit we add a benchmark to test the performance of IsPublicNode query.
This commit is contained in:
1 file changed
+24
@@ -1640,6 +1640,8 @@ func TestGraphCacheTraversal(t *testing.T) {
|
|||||||
require.Equal(t, numChannels*2*(numNodes-1), numNodeChans)
|
require.Equal(t, numChannels*2*(numNodes-1), numNodeChans)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fillTestGraph fills the graph with a given number of nodes and create a given
|
||||||
|
// number of channels between each node.
|
||||||
func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
|
func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
|
||||||
numChannels int) (map[uint64]struct{}, []*models.Node) {
|
numChannels int) (map[uint64]struct{}, []*models.Node) {
|
||||||
|
|
||||||
@@ -4042,6 +4044,28 @@ func TestNodeIsPublic(t *testing.T) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BenchmarkIsPublicNode measures the performance of IsPublicNode when checking
|
||||||
|
// a large number of nodes.
|
||||||
|
func BenchmarkIsPublicNode(b *testing.B) {
|
||||||
|
graph := MakeTestGraph(b)
|
||||||
|
|
||||||
|
// Create a graph with a reasonable number of nodes and channels.
|
||||||
|
numNodes := 100
|
||||||
|
numChans := 4
|
||||||
|
_, nodes := fillTestGraph(b, graph, numNodes, numChans)
|
||||||
|
|
||||||
|
// Use deterministic random number generator for reproducible results.
|
||||||
|
rng := prand.New(prand.NewSource(42))
|
||||||
|
|
||||||
|
for b.Loop() {
|
||||||
|
// Query random nodes to avoid query caching and better
|
||||||
|
// represent real-world query patterns.
|
||||||
|
nodePub := nodes[rng.Intn(len(nodes))].PubKeyBytes
|
||||||
|
_, err := graph.IsPublicNode(nodePub)
|
||||||
|
require.NoError(b, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestDisabledChannelIDs ensures that the disabled channels within the
|
// TestDisabledChannelIDs ensures that the disabled channels within the
|
||||||
// disabledEdgePolicyBucket are managed properly and the list returned from
|
// disabledEdgePolicyBucket are managed properly and the list returned from
|
||||||
// DisabledChannelIDs is correct.
|
// DisabledChannelIDs is correct.
|
||||||
|
|||||||
Reference in new issue
Block a user