Skip to content

Commit 9cbf05c

Browse files
committed
documentation for benchmarking using snakeviz
1 parent e3cf90f commit 9cbf05c

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ target/
6565
# python virtual env
6666
venv/
6767

68-
examples/out.png
68+
examples/out.png
69+
examples/*.perf

docs/05_benchmarking.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
# Benchmarking
22
Many pathfinding algorithms need more system resources the bigger the input grid is, some are optimized for specific scenarios to (for example Jump-Point Search) for narrow passages, while others like Dijkstra are for a general solution that come at the cost of looking at all cells of the grid in the worst case.
33

4-
## Creating a benchmark
4+
## Creating and visualizing a benchmark
55

6-
## Record performance and visualize iterations
6+
To record a run of python-pathfinding we can use the [cProfile](https://docs.python.org/3/library/profile.html)-module that comes with python3.
77

8-
http://jiffyclub.github.io/snakeviz/
8+
We can run it on the example with the loaded image to record a file named `benchmark.perf`:
9+
10+
```bash
11+
cd examples/
12+
python3 -m cProfile -o benchmark.perf image_pathfinding.py
13+
```
14+
15+
To visualize the recorded perf-file we install and run [snakeviz](http://jiffyclub.github.io/snakeviz/):
16+
17+
```bash
18+
pip3 install snakeviz
19+
snakeviz benchmark.perf
20+
```
21+
The snakeviz-ui allows you to check how long each part took and how often each function in the call stack has been executed.
22+
23+
It should look something like this:
24+
![](snakeviz_shot.png)
25+
which looks quite healthy, as it would be expected most of the time was spend on the A-Star finder, where processing the node inside the finder.py took 0.757 seconds and getting the neighbors 0.573 seconds. The rest inside pathfinding was spend on heap management. However these are also points where we could optimize most if we find a faster way to lookup nodes or use additional cache.
26+
27+
Note that process_node was called 349984 times, even if the out put in the terminal says `iterations: 176692 path length: 999`. This is because with 'iterations' we count how often we run the whole loop to processed a node including all its neighbors, while we have to run process_node for every neighbor.
928

1029
## Memory
30+
TODO

docs/snakeviz_shot.png

271 KB
Loading

0 commit comments

Comments
 (0)