Skip to content

Commit 0a2e025

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 096ab65 commit 0a2e025

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

graph/db/graph_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,8 @@ func TestGraphCacheTraversal(t *testing.T) {
15931593
require.Equal(t, numChannels*2*(numNodes-1), numNodeChans)
15941594
}
15951595

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

@@ -3995,6 +3997,25 @@ func TestNodeIsPublic(t *testing.T) {
39953997
)
39963998
}
39973999

4000+
// BenchmarkIsPublicNode measures the performance of IsPublicNode when checking
4001+
// a large number of nodes.
4002+
func BenchmarkIsPublicNode(b *testing.B) {
4003+
graph := MakeTestGraph(b)
4004+
4005+
// Create a graph with a reasonable number of nodes and channels.
4006+
numNodes := 8000
4007+
numChans := 4
4008+
_, nodes := fillTestGraph(b, graph, numNodes, numChans)
4009+
4010+
// Pick a random node to test.
4011+
nodePub := nodes[len(nodes)/2].PubKeyBytes
4012+
4013+
for b.Loop() {
4014+
_, err := graph.IsPublicNode(nodePub)
4015+
require.NoError(b, err)
4016+
}
4017+
}
4018+
39984019
// TestDisabledChannelIDs ensures that the disabled channels within the
39994020
// disabledEdgePolicyBucket are managed properly and the list returned from
40004021
// DisabledChannelIDs is correct.

0 commit comments

Comments
 (0)