Skip to content

Commit 38e6313

Browse files
committed
feat: added first benchmark
1 parent b2085cd commit 38e6313

File tree

4 files changed

+389
-120
lines changed

4 files changed

+389
-120
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ things may break randomly, or they may not even work.
2929
4. Run `poetry run pytest` to run the unit tests, or `poetry run python` to run
3030
a Python interpreter where you can `import igraph_ctypes`
3131

32+
## Benchmarking
33+
34+
Benchmarks will be placed in `benchmarks` and they will compare the "old",
35+
official Python interface of igraph with this new implementation. To run the
36+
benchmarks, type `poetry run richbench benchmarks`.
37+
3238
## Caveats
3339

3440
- Apparently you'll need to ensure that the igraph shared library is built

benchmarks/bench_shortest_path.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from random import randint
2+
3+
from igraph import Graph as LegacyGraph
4+
5+
from igraph_ctypes.constructors import create_square_lattice
6+
from igraph_ctypes.paths import get_shortest_path
7+
8+
n, k = 1000, 100
9+
10+
sources = [randint(0, n - 1) for _ in range(k)]
11+
targets = [randint(0, n - 1) for _ in range(k)]
12+
pairs = list(zip(sources, targets))
13+
14+
old_g = LegacyGraph.Lattice([n, n])
15+
new_g = create_square_lattice([n, n])
16+
17+
18+
def with_old_igraph():
19+
for u, v in pairs:
20+
old_g.get_shortest_paths(u, v)
21+
22+
23+
def with_new_igraph():
24+
for u, v in pairs:
25+
get_shortest_path(new_g, u, v)
26+
27+
28+
__benchmarks__ = [
29+
(with_old_igraph, with_new_igraph, "Finding shortest path in grid graph")
30+
]

0 commit comments

Comments
 (0)