-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'networkx:main' into wf_tests
- Loading branch information
Showing
13 changed files
with
155 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,7 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# asv | ||
results/ | ||
html/ |
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
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,22 @@ | ||
## Preview benchmarks locally | ||
|
||
1. clone this repo | ||
2. `cd benchmarks` | ||
3. If you are working on a different branch then update the `branches` in the `asv.conf.json` file. | ||
4. `asv run` will run the benchmarks on the last commit | ||
- or use `asv continuous base_commit_hash test_commit_hash` to run the benchmark to compare two commits | ||
- or `asv run -b <benchmark_file_name> -k <benchmark_name>` to run a particular benchmark. | ||
- if you are running benchmarks for the first time, you will be asked to enter your machine information after this command. | ||
5. `asv publish` will create a `html` folder with the results | ||
6. `asv preview` will host the results locally at http://127.0.0.1:8080/ | ||
|
||
<hr> | ||
|
||
## Structure of benchmarks | ||
|
||
* Each `bench_` file corresponds to a folder/file in the [networkx/algorithms](https://github.com/networkx/networkx/tree/main/networkx/algorithms) directory in NetworkX | ||
* Each class inside a `bench_` file corresponds to every file in a folder(one class if it’s a file) in networkx/algorithms | ||
* The class name corresponds to the file name and the `x` in `bench_x` corresponds to the folder name(class name and `x` are the same if it’s a file in networkx/algorithms) | ||
* Each `time_` function corresponds to each function in the file. | ||
* For other folders in [networkx/networkx](https://github.com/networkx/networkx/tree/main/networkx) like `generators`, `classes`, `linalg`, `utils` etc. we can have different `bench_` files for each of them having different classes corresponding to different files in each of these folders. | ||
* For example: `bench_centrality.py` corresponds to `networkx/algorithms/centrality` folder in NetworkX and the `Betweenness` class inside it corresponds to the `betweenness.py` file in `networkx/algorithms/centrality` folder in NetworkX. And the `time_betweenness_centrality` function corresponds to the `betweenness_centrality` function. |
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,20 @@ | ||
{ | ||
"version": 1, | ||
"project": "nx-parallel", | ||
"project_url": "https://github.com/networkx/nx-parallel", | ||
"repo": "..", | ||
"branches": ["main"], | ||
"build_command": [ | ||
"python -m pip install build", | ||
"python -m build --wheel -o {build_cache_dir} {build_dir}" | ||
], | ||
"dvcs": "git", | ||
"environment_type": "virtualenv", | ||
"show_commit_url": "https://github.com/networkx/nx-parallel/commit/", | ||
"matrix": {"networkx": ["3.2"], "nx-parallel": []}, | ||
"benchmark_dir": "benchmarks", | ||
"env_dir": "env", | ||
"results_dir": "results", | ||
"html_dir": "html", | ||
"build_cache_size": 8 | ||
} |
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 @@ | ||
|
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,11 @@ | ||
from .common import * | ||
import networkx as nx | ||
|
||
|
||
class Betweenness(Benchmark): | ||
params = [(backends), (num_nodes), (edge_prob)] | ||
param_names = ["backend", "num_nodes", "edge_prob"] | ||
|
||
def time_betweenness_centrality(self, backend, num_nodes, edge_prob): | ||
G = get_cached_gnp_random_graph(num_nodes, edge_prob) | ||
_ = nx.betweenness_centrality(G, backend=backend) |
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,11 @@ | ||
from .common import * | ||
import networkx as nx | ||
|
||
|
||
class EfficiencyMeasures(Benchmark): | ||
params = [(backends), (num_nodes), (edge_prob)] | ||
param_names = ["backend", "num_nodes", "edge_prob"] | ||
|
||
def time_local_efficiency(self, backend, num_nodes, edge_prob): | ||
G = get_cached_gnp_random_graph(num_nodes, edge_prob) | ||
_ = nx.local_efficiency(G, backend=backend) |
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,11 @@ | ||
from .common import * | ||
import networkx as nx | ||
|
||
|
||
class Isolate(Benchmark): | ||
params = [(backends), (num_nodes), (edge_prob)] | ||
param_names = ["backend", "num_nodes", "edge_prob"] | ||
|
||
def time_number_of_isolates(self, backend, num_nodes, edge_prob): | ||
G = get_cached_gnp_random_graph(num_nodes, edge_prob) | ||
_ = nx.number_of_isolates(G, backend=backend) |
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,11 @@ | ||
from .common import * | ||
import networkx as nx | ||
|
||
|
||
class Weighted(Benchmark): | ||
params = [(backends), (num_nodes), (edge_prob)] | ||
param_names = ["backend", "num_nodes", "edge_prob"] | ||
|
||
def time_all_pairs_bellman_ford_path(self, backend, num_nodes, edge_prob): | ||
G = get_cached_gnp_random_graph(num_nodes, edge_prob, is_weighted=True) | ||
_ = dict(nx.all_pairs_bellman_ford_path(G, backend=backend)) |
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,11 @@ | ||
from .common import * | ||
import networkx as nx | ||
|
||
|
||
class Tournament(Benchmark): | ||
params = [(backends), (num_nodes)] | ||
param_names = ["backend", "num_nodes"] | ||
|
||
def time_is_reachable(self, backend, num_nodes): | ||
G = nx.tournament.random_tournament(num_nodes, seed=42) | ||
_ = nx.tournament.is_reachable(G, 1, num_nodes, backend=backend) |
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,11 @@ | ||
from .common import * | ||
import networkx as nx | ||
|
||
|
||
class Vitality(Benchmark): | ||
params = [(backends), (num_nodes), (edge_prob)] | ||
param_names = ["backend", "num_nodes", "edge_prob"] | ||
|
||
def time_closeness_vitality(self, backend, num_nodes, edge_prob): | ||
G = get_cached_gnp_random_graph(num_nodes, edge_prob) | ||
_ = nx.closeness_vitality(G, backend=backend) |
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,33 @@ | ||
from functools import lru_cache | ||
from pathlib import Path | ||
import random | ||
|
||
import networkx as nx | ||
|
||
__all__ = [ | ||
"backends", | ||
"num_nodes", | ||
"edge_prob", | ||
"get_cached_gnp_random_graph", | ||
"Benchmark", | ||
] | ||
|
||
CACHE_ROOT = Path(__file__).resolve().parent.parent / "env" / "nxp_benchdata" | ||
|
||
backends = ["parallel", None] | ||
num_nodes = [50, 100, 200, 400, 800] | ||
edge_prob = [0.8, 0.6, 0.4, 0.2] | ||
|
||
|
||
@lru_cache(typed=True) | ||
def get_cached_gnp_random_graph(num_nodes, edge_prob, is_weighted=False): | ||
G = nx.fast_gnp_random_graph(num_nodes, edge_prob, seed=42, directed=False) | ||
if is_weighted: | ||
random.seed(42) | ||
for (u, v) in G.edges(): | ||
G.edges[u, v]["weight"] = random.random() | ||
return G | ||
|
||
|
||
class Benchmark: | ||
pass |
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