Skip to content

Commit dbb235a

Browse files
committed
Line Profiler
1 parent 81ad53f commit dbb235a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,13 +1063,14 @@ type(<class_name>, <parents_tuple>, <attributes_dict>)
10631063
>>> z = Z()
10641064
```
10651065

1066-
### MetaClass
1067-
#### Class that creates class:
1066+
### Meta Class
1067+
#### Class that creates class.
10681068
```python
10691069
def my_meta_class(name, parents, attrs):
10701070
...
10711071
return type(name, parents, attrs)
10721072
```
1073+
10731074
#### Or:
10741075
```python
10751076
class MyMetaClass(type):
@@ -1406,6 +1407,26 @@ timeit('"-".join(str(a) for a in range(100))',
14061407
number=10000, globals=globals())
14071408
```
14081409

1410+
### Line Profiler
1411+
```python
1412+
# $ pip3 install line_profiler
1413+
@profile
1414+
def main():
1415+
a = [(i%3 + 1) * 3 for i in range(10000)]
1416+
b = [i ** (i/10000) for i in range(10000)]
1417+
main()
1418+
```
1419+
1420+
```bash
1421+
$ kernprof -lv test.py
1422+
Line # Hits Time Per Hit % Time Line Contents
1423+
==============================================================
1424+
2 @profile
1425+
3 def main():
1426+
4 1 2901.0 2901.0 45.2 a = [(i%3 + 1) * 3 for i in range(10000)]
1427+
5 1 3518.0 3518.0 54.8 b = [i ** (i/10000) for i in range(10000)]
1428+
```
1429+
14091430
### Call Graph
14101431
#### Generates a PNG image of call graph with highlighted bottlenecks:
14111432
```python

0 commit comments

Comments
 (0)