Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ dmypy.json

# Pyre type checker
.pyre/

# asv
results/
html/
10 changes: 10 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Preview benchmarks locally

1. clone this repo
2. `cd benchmarks`
3. `asv run` will run the benchmarks on 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 would be asked to enter your machine information after this command.
4. `asv publish` will create a `html` folder with the results
5. `asv preview` will host the results locally at http://127.0.0.1:8080/
40 changes: 40 additions & 0 deletions benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"version": 1,

"project": "nx-parallel",

"project_url": "https://github.com/networkx/nx-parallel",

"repo": "..",

"branches": ["main"],

"build_command": [
"python -m pip install build hatchling",
"python -m build .",
"PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
],

"install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"],

"dvcs": "git",

"environment_type": "virtualenv",

"show_commit_url": "https://github.com/networkx/nx-parallel/commit/",

"matrix": {
"networkx":[],
"nx-parallel": []
},

"benchmark_dir": "benchmarks",

"env_dir": "env",

"results_dir": "results",

"html_dir": "html",

"build_cache_size": 8
}
Empty file.
11 changes: 11 additions & 0 deletions benchmarks/benchmarks/bench_centrality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .common import *

class Betweenness(Benchmark):
params = [(algo_types),
(num_nodes),
(edge_prob)
]
param_names = ["algo_type", "num_nodes", "edge_prob"]

def time_betweenness_centrality(self, algo_type, num_nodes, edge_prob):
timing_func(get_graph(num_nodes, edge_prob), algo_type, func = nx.betweenness_centrality)
9 changes: 9 additions & 0 deletions benchmarks/benchmarks/bench_efficiency_measures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .common import *

class EfficiencyMeasures(Benchmark):
params = [(algo_types), (num_nodes), (edge_prob)]
param_names = ["algo_type", "num_nodes", "edge_prob"]

def time_local_efficiency(self, algotype, num_nodes, edge_prob):
timing_func(get_graph(num_nodes, edge_prob), algotype, func = nx.local_efficiency)

8 changes: 8 additions & 0 deletions benchmarks/benchmarks/bench_isolate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .common import *

class Isolate(Benchmark):
params = [(algo_types), (num_nodes), (edge_prob)]
param_names = ["algo_type", "num_nodes", "edge_prob"]

def time_number_of_isolates(self, algo_type, num_nodes, edge_prob):
timing_func(get_graph(num_nodes, edge_prob), algo_type, func = nx.number_of_isolates)
13 changes: 13 additions & 0 deletions benchmarks/benchmarks/bench_tournament.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .common import *

def get_tournament_graph(num, seed = 42):
return nx.tournament.random_tournament(num, seed = seed)


class Tournament(Benchmark):
params = [(algo_types), (num_nodes)]
param_names = ["algo_type", "num_nodes"]

def time_is_reachable(self, algo_type, num_nodes):
G = get_tournament_graph(num_nodes)
timing_func(G, algo_type, nx.tournament.is_reachable, 1, num_nodes)
8 changes: 8 additions & 0 deletions benchmarks/benchmarks/bench_vitality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .common import *

class Vitality(Benchmark):
params = [(algo_types), (num_nodes), (edge_prob)]
param_names = ["algo_type", "num_nodes", "edge_prob"]

def time_closeness_vitality(self, algo_type, num_nodes, edge_prob):
timing_func(get_graph(num_nodes, edge_prob), algo_type, func = nx.closeness_vitality)
42 changes: 42 additions & 0 deletions benchmarks/benchmarks/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from functools import lru_cache
from pathlib import Path
import types
import random

import networkx as nx
import nx_parallel as nxp


CACHE_ROOT = Path(__file__).resolve().parent.parent / 'env' / 'nxp_benchdata'

algo_types = ["parallel", "sequential"]
num_nodes = [10, 50, 100, 300, 500]
edge_prob = [1, 0.8, 0.6, 0.4, 0.2]

@lru_cache(typed=True)
def get_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

def timing_func(G, algo_type, func, *args, **kwargs):
if algo_type == "parallel":
H = nxp.ParallelGraph(G)
_ = func(H, *args, **kwargs)
if type(_)==types.GeneratorType: d = dict(_)
elif algo_type == "sequential":
_ = func(G, *args, **kwargs)
if type(_)==types.GeneratorType: d = dict(_)
# if you want to use the following, then pls add "using_kwargs" in `algo_types` above in line 12
#elif algo_type == "using_kwargs":
# _ = func(G, *args, **kwargs, backend='parallel')
# if type(_)==types.GeneratorType: d = dict(_)
else:
raise ValueError("Unknown algo_type")


class Benchmark:
pass