From dbb235a855db422072246e3cb8c873c8295a8ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 2 Jan 2019 01:40:21 +0100 Subject: [PATCH] Line Profiler --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2091e86..ee02cbf 100644 --- a/README.md +++ b/README.md @@ -1063,13 +1063,14 @@ type(, , ) >>> z = Z() ``` -### MetaClass -#### Class that creates class: +### Meta Class +#### Class that creates class. ```python def my_meta_class(name, parents, attrs): ... return type(name, parents, attrs) ``` + #### Or: ```python class MyMetaClass(type): @@ -1406,6 +1407,26 @@ timeit('"-".join(str(a) for a in range(100))', number=10000, globals=globals()) ``` +### Line Profiler +```python +# $ pip3 install line_profiler +@profile +def main(): + a = [(i%3 + 1) * 3 for i in range(10000)] + b = [i ** (i/10000) for i in range(10000)] +main() +``` + +```bash +$ kernprof -lv test.py +Line # Hits Time Per Hit % Time Line Contents +============================================================== + 2 @profile + 3 def main(): + 4 1 2901.0 2901.0 45.2 a = [(i%3 + 1) * 3 for i in range(10000)] + 5 1 3518.0 3518.0 54.8 b = [i ** (i/10000) for i in range(10000)] +``` + ### Call Graph #### Generates a PNG image of call graph with highlighted bottlenecks: ```python