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:
Abdullahi Yunus committed 2025-12-23 21:04:36 +01:00
1 parent 013f5c93ed
commit 86cde4b93f
1 file changed
+24
+24
View File
@@ -1640,6 +1640,8 @@ func TestGraphCacheTraversal(t *testing.T) {
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,
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
// disabledEdgePolicyBucket are managed properly and the list returned from
// DisabledChannelIDs is correct.