Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyperformance/data-files/benchmarks/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ logging <local>
mako <local>
mdp <local>
meteor_contest <local>
networkx <local>
networkx_connected_components <local:networkx>
networkx_k_core <local:networkx>
nbody <local>
nqueens <local>
pathlib <local>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.pyperformance]
name = "networkx_connected_components"
extra_opts = ["connected_components"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.pyperformance]
name = "networkx_k_core"
extra_opts = ["k_core"]
Binary file not shown.
13 changes: 13 additions & 0 deletions pyperformance/data-files/benchmarks/bm_networkx/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "pyperformance_bm_networkx"
requires-python = ">=3.11"
dependencies = [
"pyperf",
"networkx",
]
urls.repository = "https://github.com/python/pyperformance"
dynamic = ["version"]

[tool.pyperformance]
name = "networkx_shortest_path"
extra_opts = ["shortest_path"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
networkx==3.4.2
61 changes: 61 additions & 0 deletions pyperformance/data-files/benchmarks/bm_networkx/run_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Some graph algorithm benchmarks using networkx

This uses the public domain Amazon data set from the SNAP benchmarks:

https://snap.stanford.edu/data/amazon0302.html

Choice of benchmarks inspired by Timothy Lin's work here:

https://www.timlrx.com/blog/benchmark-of-popular-graph-network-packages
"""

import collections
from pathlib import Path

import networkx

import pyperf


DATA_FILE = Path(__file__).parent / "data" / "amazon0302.txt.gz"


graph = networkx.read_adjlist(DATA_FILE)


def bench_shortest_path():
collections.deque(networkx.shortest_path_length(graph, "0"))


def bench_connected_components():
networkx.number_connected_components(graph)


def bench_k_core():
networkx.k_core(graph)


BENCHMARKS = {
"shortest_path": bench_shortest_path,
"connected_components": bench_connected_components,
"k_core": bench_k_core,
}


def add_cmdline_args(cmd, args):
cmd.append(args.benchmark)


def add_parser_args(parser):
parser.add_argument("benchmark", choices=BENCHMARKS, help="Which benchmark to run.")


if __name__ == "__main__":
runner = pyperf.Runner(add_cmdline_args=add_cmdline_args)
runner.metadata["description"] = "NetworkX benchmark"
add_parser_args(runner.argparser)
args = runner.parse_args()
benchmark = args.benchmark

runner.bench_func(args.benchmark, BENCHMARKS[args.benchmark])