Skip to content

Commit

Permalink
Add benchmarks for common_neighbors.
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbar committed Jan 25, 2024
1 parent bcd2d2e commit 6a36798
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions benchmarks/benchmarks/benchmark_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,23 @@ def time_path_last(self, num_nodes):

def time_path_center(self, num_nodes):
set(nx.non_neighbors(self.path_graph, num_nodes // 2))


# NOTE: explicit set construction in benchmarks is required for meaningful
# comparisons due to change in return type from generator -> set. See gh-7244.
class CommonNeighbors:
param_names = ["num_nodes"]
params = [10, 100, 1000]

def setup(self, num_nodes):
self.star_graph = nx.star_graph(num_nodes)
self.complete_graph = nx.complete_graph(num_nodes)

def time_star_center_rim(self, num_nodes):
set(nx.common_neighbors(self.star_graph, 0, num_nodes // 2))

def time_star_rim_rim(self, num_nodes):
set(nx.common_neighbors(self.star_graph, 4, 5))

def time_complete(self, num_nodes):
set(nx.common_neighbors(self.complete_graph, 0, num_nodes // 2))

0 comments on commit 6a36798

Please sign in to comment.