Skip to content

Instantly share code, notes, and snippets.

@IvanIsCoding
Created May 4, 2025 17:43
Show Gist options
  • Save IvanIsCoding/58157618e75a0c6aaf699dc5882d7829 to your computer and use it in GitHub Desktop.
Save IvanIsCoding/58157618e75a0c6aaf699dc5882d7829 to your computer and use it in GitHub Desktop.
rustworkx foldhash vs ahash benchmark
(base) ➜ minibench uv run released_rustworkx.py
Python version: 3.12.3 | packaged by Anaconda, Inc. | (main, May 6 2024, 14:46:42) [Clang 14.0.6 ]
rustworkx version: 0.16.0
Dijkstra on directed path graph with 100000 nodes (run 100 times) took on average 0.6737 ± 0.0607 seconds
(base) ➜ minibench uv run experimental_rustworkx.py
Python version: 3.12.3 | packaged by Anaconda, Inc. | (main, May 6 2024, 14:46:42) [Clang 14.0.6 ]
rustworkx version: 0.17.0
Dijkstra on directed path graph with 100000 nodes (run 100 times) took on average 0.6434 ± 0.0024 seconds
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "rustworkx==0.16.0",
# ]
# ///
import rustworkx as rx
import sys
import timeit
import statistics
def benchmark():
N = 100_000
graph = rx.generators.directed_path_graph(N)
def run():
# Benchmark Dijkstra from node 0
rx.dijkstra_shortest_path_lengths(graph, 0, edge_cost_fn=lambda _: 1.0)
times = timeit.repeat(run, number=100, repeat=10)
avg_time = statistics.mean(times)
stddev_time = statistics.stdev(times)
print(f"Dijkstra on directed path graph with {N} nodes (run 100 times) took on average {avg_time:.4f} ± {stddev_time:.4f} seconds")
if __name__ == "__main__":
print(f"Python version: {sys.version}")
print(f"rustworkx version: {rx.__version__}")
benchmark()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment