Skip to content

Commit

Permalink
Add basic benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Nov 21, 2024
1 parent 3260183 commit 00a4a4a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions benchmarks/nx-cugraph/pytest-based/bench_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import random
from collections.abc import Mapping

import networkx as nx
Expand Down Expand Up @@ -844,6 +845,36 @@ def bench_ego_graph(benchmark, graph_obj, backend_wrapper):
assert isinstance(result, (nx.Graph, nxcg.Graph))


def bench_lowest_common_ancestor(benchmark, graph_obj, backend_wrapper):
# Must be DAG
if not nx.is_directed_acyclic_graph(graph_obj):
new_graph_obj = nx.DiGraph()
new_graph_obj.add_nodes_from(graph_obj.nodes(data=True))
new_graph_obj.add_edges_from(
(src, dst, *rest)
for src, dst, *rest in graph_obj.edges(data=True)
if src < dst
)
new_graph_obj.graph.update(graph_obj.graph)
print(
f"WARNING: graph was changed and now had {new_graph_obj.number_of_nodes()} "
"nodes and {new_graph_obj.number_of_edges()} edges."
)
graph_obj = new_graph_obj

G = get_graph_obj_for_benchmark(graph_obj, backend_wrapper)
r = random.Random(42)
node1, node2 = r.sample(sorted(G), 2)
result = benchmark.pedantic(
target=backend_wrapper(nx.lowest_common_ancestor),
args=(G, node1, node2),
rounds=rounds,
iterations=iterations,
warmup_rounds=warmup_rounds,
)
assert result is None or result in G


@pytest.mark.skip(reason="benchmark not implemented")
def bench_complete_bipartite_graph(benchmark, graph_obj, backend_wrapper):
pass
Expand Down

0 comments on commit 00a4a4a

Please sign in to comment.