From 8adc71ce068aad32f9d7d47d717dc0a36a8561ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 29 Nov 2023 23:11:08 +0100 Subject: [PATCH] Profiling --- README.md | 29 ++++++++++++++--------------- index.html | 33 ++++++++++++++++----------------- parse.js | 23 +++++++++++------------ 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index b8ab554..0a74eff 100644 --- a/README.md +++ b/README.md @@ -2605,12 +2605,12 @@ def main(): b = set(range(10000)) main()' > test.py $ kernprof -lv test.py -Line # Hits Time Per Hit % Time Line Contents -======================================================= - 1 @profile - 2 def main(): - 3 1 219.0 219.0 31.1 a = list(range(10000)) - 4 1 487.0 487.0 68.9 b = set(range(10000)) +Line # Hits Time Per Hit % Time Line Contents +============================================================== + 1 @profile + 2 def main(): + 3 1 253.4 253.4 32.2 a = list(range(10000)) + 4 1 534.1 534.1 67.8 b = set(range(10000)) ``` ### Call and Flame Graphs @@ -2624,15 +2624,14 @@ $ snakeviz test.prof ### Sampling and Memory Profilers ```text -+--------------+-------------------------------+------------+----------+------+ -| pip3 install | How to run | Target | Type | Live | -+--------------+-------------------------------+------------+----------+------+ -| py-spy | py-spy top -- python3 test.py | CPU | Sampling | Yes | -| pyinstrument | pyinstrument test.py | CPU | Sampling | No | -| scalene | scalene test.py | CPU+Memory | Sampling | No | -| memray | memray run --live test.py | Memory | Tracing | Yes | -| filprofiler | fil-profile run test.py | Memory | Tracing | No | -+--------------+-------------------------------+------------+----------+------+ ++--------------+----------+------------+-------------------------------+------+ +| pip3 install | Type | Target | How to run | Live | ++--------------+----------+------------+-------------------------------+------+ +| pyinstrument | Sampling | CPU | pyinstrument test.py | No | +| py-spy | Sampling | CPU | py-spy top -- python3 test.py | Yes | +| scalene | Sampling | CPU+Memory | scalene test.py | No | +| memray | Tracing | Memory | memray run --live test.py | Yes | ++--------------+----------+------------+-------------------------------+------+ ``` diff --git a/index.html b/index.html index 2c0eddd..4c6aada 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -2130,12 +2130,12 @@ def main(): b = set(range(10000)) main()' > test.py $ kernprof -lv test.py -Line # Hits Time Per Hit % Time Line Contents -======================================================= - 1 @profile - 2 def main(): - 3 1 219.0 219.0 31.1 a = list(range(10000)) - 4 1 487.0 487.0 68.9 b = set(range(10000)) +Line # Hits Time Per Hit % Time Line Contents +============================================================== + 1 @profile + 2 def main(): + 3 1 253.4 253.4 32.2 a = list(range(10000)) + 4 1 534.1 534.1 67.8 b = set(range(10000))

Call and Flame Graphs

$ pip3 install gprof2dot snakeviz; apt/brew install graphviz
@@ -2145,15 +2145,14 @@ $ gprof2dot -f pstats test.prof | dot -T png -o test.png; xdg-open/open test.png
 $ snakeviz test.prof
 
-

Sampling and Memory Profilers

┏━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━┓
-┃ pip3 install │          How to run           │   Target   │   Type   │ Live ┃
-┠──────────────┼───────────────────────────────┼────────────┼──────────┼──────┨
-┃ py-spy       │ py-spy top -- python3 test.py │    CPU     │ Sampling │ Yes  ┃
-┃ pyinstrument │ pyinstrument test.py          │    CPU     │ Sampling │ No   ┃
-┃ scalene      │ scalene test.py               │ CPU+Memory │ Sampling │ No   ┃
-┃ memray       │ memray run --live test.py     │   Memory   │ Tracing  │ Yes  ┃
-┃ filprofiler  │ fil-profile run test.py       │   Memory   │ Tracing  │ No   ┃
-┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━┛
+

Sampling and Memory Profilers

┏━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━┓
+┃ pip3 install │   Type   │   Target   │          How to run           │ Live ┃
+┠──────────────┼──────────┼────────────┼───────────────────────────────┼──────┨
+┃ pyinstrument │ Sampling │    CPU     │ pyinstrument test.py          │  ×   ┃
+┃ py-spy       │ Sampling │    CPU     │ py-spy top -- python3 test.py │  ✓   ┃
+┃ scalene      │ Sampling │ CPU+Memory │ scalene test.py               │  ×   ┃
+┃ memray       │ Tracing  │   Memory   │ memray run --live test.py     │  ✓   ┃
+┗━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━┛
 

#NumPy

Array manipulation mini-language. It can run up to one hundred times faster than the equivalent Python code. An even faster alternative that runs on a GPU is called CuPy.

# $ pip3 install numpy
@@ -2926,7 +2925,7 @@ $ deactivate                  # Deactivates the activ
  
 
   
 
diff --git a/parse.js b/parse.js
index 13b4284..5f31ca7 100755
--- a/parse.js
+++ b/parse.js
@@ -517,20 +517,19 @@ const DIAGRAM_11_B =
   '┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
 
 const DIAGRAM_115_A =
-  '+--------------+-------------------------------+------------+----------+------+\n' +
-  '| pip3 install |          How to run           |   Target   |   Type   | Live |\n' +
-  '+--------------+-------------------------------+------------+----------+------+\n';
+  '+--------------+----------+------------+-------------------------------+------+\n' +
+  '| pip3 install |   Type   |   Target   |          How to run           | Live |\n' +
+  '+--------------+----------+------------+-------------------------------+------+\n';
 
 const DIAGRAM_115_B =
-  '┏━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━┓\n' +
-  '┃ pip3 install │          How to run           │   Target   │   Type   │ Live ┃\n' +
-  '┠──────────────┼───────────────────────────────┼────────────┼──────────┼──────┨\n' +
-  '┃ py-spy       │ py-spy top -- python3 test.py │    CPU     │ Sampling │ Yes  ┃\n' +
-  '┃ pyinstrument │ pyinstrument test.py          │    CPU     │ Sampling │ No   ┃\n' +
-  '┃ scalene      │ scalene test.py               │ CPU+Memory │ Sampling │ No   ┃\n' +
-  '┃ memray       │ memray run --live test.py     │   Memory   │ Tracing  │ Yes  ┃\n' +
-  '┃ filprofiler  │ fil-profile run test.py       │   Memory   │ Tracing  │ No   ┃\n' +
-  '┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━┛\n';
+  '┏━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━┓\n' +
+  '┃ pip3 install │   Type   │   Target   │          How to run           │ Live ┃\n' +
+  '┠──────────────┼──────────┼────────────┼───────────────────────────────┼──────┨\n' +
+  '┃ pyinstrument │ Sampling │    CPU     │ pyinstrument test.py          │  ×   ┃\n' +
+  '┃ py-spy       │ Sampling │    CPU     │ py-spy top -- python3 test.py │  ✓   ┃\n' +
+  '┃ scalene      │ Sampling │ CPU+Memory │ scalene test.py               │  ×   ┃\n' +
+  '┃ memray       │ Tracing  │   Memory   │ memray run --live test.py     │  ✓   ┃\n' +
+  '┗━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━┛\n';
 
 const DIAGRAM_12_A =
   '+-----------+-----------+------+-----------+\n' +