-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add some NetworkX benchmarks * Fix toml files * Try to get tests to pass * Fix typo
- Loading branch information
Showing
7 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
pyperformance/data-files/benchmarks/bm_networkx/bm_networkx_connected_components.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[tool.pyperformance] | ||
name = "networkx_connected_components" | ||
extra_opts = ["connected_components"] |
3 changes: 3 additions & 0 deletions
3
pyperformance/data-files/benchmarks/bm_networkx/bm_networkx_k_core.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+4.45 MB
pyperformance/data-files/benchmarks/bm_networkx/data/amazon0302.txt.gz
Binary file not shown.
13 changes: 13 additions & 0 deletions
13
pyperformance/data-files/benchmarks/bm_networkx/pyproject.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
1 change: 1 addition & 0 deletions
1
pyperformance/data-files/benchmarks/bm_networkx/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
networkx==3.4.2 |
61 changes: 61 additions & 0 deletions
61
pyperformance/data-files/benchmarks/bm_networkx/run_benchmark.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |