Browse Source

Line Profiler

pull/9/head
Jure Šorn 6 years ago
parent
commit
dbb235a855
1 changed files with 23 additions and 2 deletions
  1. 25
      README.md

25
README.md

@ -1063,13 +1063,14 @@ type(<class_name>, <parents_tuple>, <attributes_dict>)
>>> z = Z() >>> z = Z()
``` ```
### MetaClass ### Meta Class
#### Class that creates class: #### Class that creates class.
```python ```python
def my_meta_class(name, parents, attrs): def my_meta_class(name, parents, attrs):
... ...
return type(name, parents, attrs) return type(name, parents, attrs)
``` ```
#### Or: #### Or:
```python ```python
class MyMetaClass(type): class MyMetaClass(type):
@ -1406,6 +1407,26 @@ timeit('"-".join(str(a) for a in range(100))',
number=10000, globals=globals()) 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 ### Call Graph
#### Generates a PNG image of call graph with highlighted bottlenecks: #### Generates a PNG image of call graph with highlighted bottlenecks:
```python ```python

|||||||
100:0
Loading…
Cancel
Save