Skip to content

Commit cf003b0

Browse files
committed
graphdb: add benchmark for isPublicNode query
In this commit we add a benchmark to test the performance of IsPublicNode query.
1 parent 00538b1 commit cf003b0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

graph/db/graph_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,8 @@ func TestGraphCacheTraversal(t *testing.T) {
16401640
require.Equal(t, numChannels*2*(numNodes-1), numNodeChans)
16411641
}
16421642

1643+
// fillTestGraph fills the graph with a given number of nodes and create a given
1644+
// number of channels between each node.
16431645
func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
16441646
numChannels int) (map[uint64]struct{}, []*models.Node) {
16451647

@@ -4042,6 +4044,29 @@ func TestNodeIsPublic(t *testing.T) {
40424044
)
40434045
}
40444046

4047+
// BenchmarkIsPublicNode measures the performance of IsPublicNode when checking
4048+
// a large number of nodes.
4049+
func BenchmarkIsPublicNode(b *testing.B) {
4050+
graph := MakeTestGraph(b)
4051+
4052+
// Create a graph with a reasonable number of nodes and channels.
4053+
numNodes := 8000
4054+
numChans := 4
4055+
_, nodes := fillTestGraph(b, graph, numNodes, numChans)
4056+
4057+
// Pick any node to test with.
4058+
nodePub := nodes[len(nodes)/2].PubKeyBytes
4059+
4060+
// Reset the timer to exclude setup time especially since
4061+
// `fillTestGraph` can take a while.
4062+
b.ResetTimer()
4063+
4064+
for b.Loop() {
4065+
_, err := graph.IsPublicNode(nodePub)
4066+
require.NoError(b, err)
4067+
}
4068+
}
4069+
40454070
// TestDisabledChannelIDs ensures that the disabled channels within the
40464071
// disabledEdgePolicyBucket are managed properly and the list returned from
40474072
// DisabledChannelIDs is correct.

0 commit comments

Comments
 (0)