SlideShare a Scribd company logo
1 of 58
Download to read offline
globo
.com Profiling em Python
Friday, October 4, 13
porque profiling é importante?
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
então vamos otimizar tudo!
Friday, October 4, 13
Friday, October 4, 13
“We should forget about small efficiencies, say
about 97% of the time: premature optimization
is the root of all evil” - Donald Knuth
Friday, October 4, 13
from timeit import timeit
if __name__ == "__main__":
setup = "from htmlmin.minify import html_minify;"
setup += "from data import raw_html"
t = timeit(
stmt="html_minify(raw_html)",
setup=setup,
number=100)
print(t)
benchmark.py
Friday, October 4, 13
$ python benchmark.py
25.8121981621
Friday, October 4, 13
conheça seu código
Friday, October 4, 13
‣ cProfile
‣ Profile
‣ hotshot (deprecated)
‣ trace
‣ line profiler
‣ memory profiler
Friday, October 4, 13
from data import raw_html
from htmlmin.minify import html_minify
if __name__ == "__main__":
html_minify(raw_html)
profile.py
Friday, October 4, 13
$ python -m cProfile profile.py
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
$ python -m cProfile -o out profile.py
Friday, October 4, 13
$ python -m cProfile -o out profile.py
Friday, October 4, 13
>>> import pstats
>>> p = pstats.Stats("out")
>>> p.sort_stats("cumulative").print_stats(10)
315165 function calls (311828 primitive calls) in 1.334 seconds
Ordered by: cumulative time
List reduced from 675 to 10 due to restriction <10>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.092 0.092 1.358 1.358 profile.py:2(<module>)
1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py:
7(<module>)
1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py:
17(<module>)
1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py:
1(<module>)
1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py:
2(<module>)
1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py:
12(<module>)
1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py:
26(html_minify)
2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py:
80(__init__)
2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py:
193(_feed)
2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py:
33(feed)
Friday, October 4, 13
>>> import pstats
>>> p = pstats.Stats("out")
>>> p.sort_stats("cumulative").print_stats(10)
315165 function calls (311828 primitive calls) in 1.334 seconds
Ordered by: cumulative time
List reduced from 675 to 10 due to restriction <10>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.092 0.092 1.358 1.358 profile.py:2(<module>)
1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py:
7(<module>)
1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py:
17(<module>)
1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py:
1(<module>)
1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py:
2(<module>)
1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py:
12(<module>)
1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py:
26(html_minify)
2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py:
80(__init__)
2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py:
193(_feed)
2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py:
33(feed)
Friday, October 4, 13
>>> import pstats
>>> p = pstats.Stats("out")
>>> p.sort_stats("cumulative").print_stats(10)
315165 function calls (311828 primitive calls) in 1.334 seconds
Ordered by: cumulative time
List reduced from 675 to 10 due to restriction <10>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.092 0.092 1.358 1.358 profile.py:2(<module>)
1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py:
7(<module>)
1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py:
17(<module>)
1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py:
1(<module>)
1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py:
2(<module>)
1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py:
12(<module>)
1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py:
26(html_minify)
2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py:
80(__init__)
2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py:
193(_feed)
2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py:
33(feed)
Friday, October 4, 13
>>> import pstats
>>> p = pstats.Stats("out")
>>> p.sort_stats("cumulative").print_stats(10)
315165 function calls (311828 primitive calls) in 1.334 seconds
Ordered by: cumulative time
List reduced from 675 to 10 due to restriction <10>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.092 0.092 1.358 1.358 profile.py:2(<module>)
1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py:
7(<module>)
1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py:
17(<module>)
1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py:
1(<module>)
1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py:
2(<module>)
1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py:
12(<module>)
1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py:
26(html_minify)
2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py:
80(__init__)
2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py:
193(_feed)
2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py:
33(feed)
Friday, October 4, 13
>>> import pstats
>>> p = pstats.Stats("out")
>>> p.sort_stats("cumulative").print_stats(10)
315165 function calls (311828 primitive calls) in 1.334 seconds
Ordered by: cumulative time
List reduced from 675 to 10 due to restriction <10>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.092 0.092 1.358 1.358 profile.py:2(<module>)
1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py:
7(<module>)
1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py:
17(<module>)
1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py:
1(<module>)
1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py:
2(<module>)
1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py:
12(<module>)
1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py:
26(html_minify)
2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py:
80(__init__)
2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py:
193(_feed)
2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py:
33(feed)
Friday, October 4, 13
>>> import pstats
>>> p = pstats.Stats("out")
>>> p.sort_stats("cumulative").print_stats(10)
315165 function calls (311828 primitive calls) in 1.334 seconds
Ordered by: cumulative time
List reduced from 675 to 10 due to restriction <10>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.092 0.092 1.358 1.358 profile.py:2(<module>)
1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py:
7(<module>)
1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py:
17(<module>)
1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py:
1(<module>)
1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py:
2(<module>)
1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py:
12(<module>)
1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py:
26(html_minify)
2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py:
80(__init__)
2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py:
193(_feed)
2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py:
33(feed)
Friday, October 4, 13
>>> import pstats
>>> p = pstats.Stats("out")
>>> p.sort_stats("cumulative").print_stats(10)
315165 function calls (311828 primitive calls) in 1.334 seconds
Ordered by: cumulative time
List reduced from 675 to 10 due to restriction <10>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.092 0.092 1.358 1.358 profile.py:2(<module>)
1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py:
7(<module>)
1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py:
17(<module>)
1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py:
1(<module>)
1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py:
2(<module>)
1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py:
12(<module>)
1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py:
26(html_minify)
2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py:
80(__init__)
2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py:
193(_feed)
2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py:
33(feed)
Friday, October 4, 13
$ kernprof.py -l -v minify.py
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
$ python -m memory_profiler minify.py
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
gui?
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
outras ferramentas
‣ meliae
‣ heapy (guppy)
‣ benchy
‣ valgrind
‣ python object graphs (objgraph)
‣ plop
‣ pycounters
Friday, October 4, 13
bônus
Friday, October 4, 13
django profiling
Friday, October 4, 13
algumas ferramentas
‣ django-debug-toolbar
‣ django-profiler
‣ new relic
Friday, October 4, 13
Friday, October 4, 13
$ newrelic-admin run-program gunicorn -w 3
wsgi:application
Friday, October 4, 13
Friday, October 4, 13
globo
.com Estamos contratando!
Friday, October 4, 13
globo
.com
obrigada!
@flaviamissi
Friday, October 4, 13

More Related Content

What's hot

Python testing-frameworks overview
Python testing-frameworks overviewPython testing-frameworks overview
Python testing-frameworks overviewJachym Cepicky
 
Python sqlite3 - flask
Python   sqlite3 - flaskPython   sqlite3 - flask
Python sqlite3 - flaskEueung Mulyana
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...akaptur
 
Down the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoDown the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoRemco Wendt
 
寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)均民 戴
 
Something about Golang
Something about GolangSomething about Golang
Something about GolangAnton Arhipov
 
寫程式?那些老師沒教的事
寫程式?那些老師沒教的事寫程式?那些老師沒教的事
寫程式?那些老師沒教的事均民 戴
 
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...Raman Kannan
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
Abusing Erlang compilation pipeline for Fun and Profit
Abusing Erlang compilation pipeline for Fun and ProfitAbusing Erlang compilation pipeline for Fun and Profit
Abusing Erlang compilation pipeline for Fun and ProfitWojciech Gawroński
 
Accessing File-Specific Attributes on Steroids - EuroPython 2008
Accessing File-Specific Attributes on Steroids - EuroPython 2008Accessing File-Specific Attributes on Steroids - EuroPython 2008
Accessing File-Specific Attributes on Steroids - EuroPython 2008Dinu Gherman
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in Rmickey24
 
The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180Mahmoud Samir Fayed
 

What's hot (19)

Python testing-frameworks overview
Python testing-frameworks overviewPython testing-frameworks overview
Python testing-frameworks overview
 
Python sqlite3 - flask
Python   sqlite3 - flaskPython   sqlite3 - flask
Python sqlite3 - flask
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
 
Down the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoDown the rabbit hole, profiling in Django
Down the rabbit hole, profiling in Django
 
寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
寫程式?那些老師沒教的事
寫程式?那些老師沒教的事寫程式?那些老師沒教的事
寫程式?那些老師沒教的事
 
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
 
Abusing Erlang compilation pipeline for Fun and Profit
Abusing Erlang compilation pipeline for Fun and ProfitAbusing Erlang compilation pipeline for Fun and Profit
Abusing Erlang compilation pipeline for Fun and Profit
 
Docopt
DocoptDocopt
Docopt
 
Python modulesfinal
Python modulesfinalPython modulesfinal
Python modulesfinal
 
4 Sessions
4 Sessions4 Sessions
4 Sessions
 
Accessing File-Specific Attributes on Steroids - EuroPython 2008
Accessing File-Specific Attributes on Steroids - EuroPython 2008Accessing File-Specific Attributes on Steroids - EuroPython 2008
Accessing File-Specific Attributes on Steroids - EuroPython 2008
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in R
 
The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180
 
wreewrer
wreewrerwreewrer
wreewrer
 

Viewers also liked

2011 03 mobil.sk
2011 03 mobil.sk2011 03 mobil.sk
2011 03 mobil.skOneClick
 
Media studies final evaluation
Media studies  final evaluationMedia studies  final evaluation
Media studies final evaluationwilzy92
 
2011 04 f1.sk
2011 04 f1.sk2011 04 f1.sk
2011 04 f1.skOneClick
 
2011 06 beauty.sk
2011 06 beauty.sk2011 06 beauty.sk
2011 06 beauty.skOneClick
 
2011 10 auto.sk
2011 10 auto.sk2011 10 auto.sk
2011 10 auto.skOneClick
 
OneClick Media Cennik 2011
OneClick Media Cennik 2011OneClick Media Cennik 2011
OneClick Media Cennik 2011OneClick
 
2011 04 point network
2011 04 point network2011 04 point network
2011 04 point networkOneClick
 
2011 04 profutbal.sk
2011 04 profutbal.sk2011 04 profutbal.sk
2011 04 profutbal.skOneClick
 
Django class based-views
Django class based-viewsDjango class based-views
Django class based-viewsFlavian Missi
 
JOB ANALYSIS AND HUMAN RESOURCE PLANNING
JOB ANALYSIS AND HUMAN RESOURCE PLANNINGJOB ANALYSIS AND HUMAN RESOURCE PLANNING
JOB ANALYSIS AND HUMAN RESOURCE PLANNINGMuhammad Farhan Javed
 
Innovative HRM Practices at IKEA
Innovative HRM Practices at IKEAInnovative HRM Practices at IKEA
Innovative HRM Practices at IKEAPrasant Patro
 
Human Resource Planning and Job Analysis
Human Resource Planning and Job AnalysisHuman Resource Planning and Job Analysis
Human Resource Planning and Job AnalysisHaris Bin Zahid
 
Example H R Strategy & Vision
Example  H R  Strategy &  VisionExample  H R  Strategy &  Vision
Example H R Strategy & Visionlongda
 
Techniques for Forecasting Human Resources
Techniques  for Forecasting   Human ResourcesTechniques  for Forecasting   Human Resources
Techniques for Forecasting Human ResourcesBHOMA RAM
 
HR Strategy: What is it? Why do we need it?
HR Strategy: What is it? Why do we need it?HR Strategy: What is it? Why do we need it?
HR Strategy: What is it? Why do we need it?CreativeHRM
 
Example of HRM Strategy - IKEA
Example of HRM Strategy - IKEAExample of HRM Strategy - IKEA
Example of HRM Strategy - IKEAMirna Babović
 

Viewers also liked (20)

2011 03 mobil.sk
2011 03 mobil.sk2011 03 mobil.sk
2011 03 mobil.sk
 
Media studies final evaluation
Media studies  final evaluationMedia studies  final evaluation
Media studies final evaluation
 
2011 04 f1.sk
2011 04 f1.sk2011 04 f1.sk
2011 04 f1.sk
 
2011 06 beauty.sk
2011 06 beauty.sk2011 06 beauty.sk
2011 06 beauty.sk
 
2011 10 auto.sk
2011 10 auto.sk2011 10 auto.sk
2011 10 auto.sk
 
OneClick Media Cennik 2011
OneClick Media Cennik 2011OneClick Media Cennik 2011
OneClick Media Cennik 2011
 
2011 04 point network
2011 04 point network2011 04 point network
2011 04 point network
 
2011 04 profutbal.sk
2011 04 profutbal.sk2011 04 profutbal.sk
2011 04 profutbal.sk
 
Django class based-views
Django class based-viewsDjango class based-views
Django class based-views
 
Job analysis & HR Planning- Sem Shaikh
Job analysis & HR Planning- Sem ShaikhJob analysis & HR Planning- Sem Shaikh
Job analysis & HR Planning- Sem Shaikh
 
JOB ANALYSIS AND HUMAN RESOURCE PLANNING
JOB ANALYSIS AND HUMAN RESOURCE PLANNINGJOB ANALYSIS AND HUMAN RESOURCE PLANNING
JOB ANALYSIS AND HUMAN RESOURCE PLANNING
 
Job analyses and hr planning
Job analyses and hr planningJob analyses and hr planning
Job analyses and hr planning
 
Innovative HRM Practices at IKEA
Innovative HRM Practices at IKEAInnovative HRM Practices at IKEA
Innovative HRM Practices at IKEA
 
Human Resource Planning and Job Analysis
Human Resource Planning and Job AnalysisHuman Resource Planning and Job Analysis
Human Resource Planning and Job Analysis
 
Example H R Strategy & Vision
Example  H R  Strategy &  VisionExample  H R  Strategy &  Vision
Example H R Strategy & Vision
 
Techniques for Forecasting Human Resources
Techniques  for Forecasting   Human ResourcesTechniques  for Forecasting   Human Resources
Techniques for Forecasting Human Resources
 
HR Strategy: What is it? Why do we need it?
HR Strategy: What is it? Why do we need it?HR Strategy: What is it? Why do we need it?
HR Strategy: What is it? Why do we need it?
 
Fundamentals of HRM
Fundamentals of HRMFundamentals of HRM
Fundamentals of HRM
 
Demand forecasting ppt
Demand forecasting pptDemand forecasting ppt
Demand forecasting ppt
 
Example of HRM Strategy - IKEA
Example of HRM Strategy - IKEAExample of HRM Strategy - IKEA
Example of HRM Strategy - IKEA
 

Similar to Python Profiling Tools Optimize Code Performance

Pygrunn 2012 down the rabbit - profiling in python
Pygrunn 2012   down the rabbit - profiling in pythonPygrunn 2012   down the rabbit - profiling in python
Pygrunn 2012 down the rabbit - profiling in pythonRemco Wendt
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 
NetConf 2018 BPF Observability
NetConf 2018 BPF ObservabilityNetConf 2018 BPF Observability
NetConf 2018 BPF ObservabilityBrendan Gregg
 
MySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkMySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkLouis liu
 
How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]Devon Bernard
 
Reutov, yunusov, nagibin random numbers take ii
Reutov, yunusov, nagibin   random numbers take iiReutov, yunusov, nagibin   random numbers take ii
Reutov, yunusov, nagibin random numbers take iiDefconRussia
 
Best Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesBest Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesOdoo
 
EKON22 Introduction to Machinelearning
EKON22 Introduction to MachinelearningEKON22 Introduction to Machinelearning
EKON22 Introduction to MachinelearningMax Kleiner
 
Python update in 2018 #ll2018jp
Python update in 2018 #ll2018jpPython update in 2018 #ll2018jp
Python update in 2018 #ll2018jpcocodrips
 
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...Piotr Przymus
 
Divolte Collector - meetup presentation
Divolte Collector - meetup presentationDivolte Collector - meetup presentation
Divolte Collector - meetup presentationfvanvollenhoven
 
What I learned about IoT Security ... and why it's so hard!
What I learned about IoT Security ... and why it's so hard!What I learned about IoT Security ... and why it's so hard!
What I learned about IoT Security ... and why it's so hard!Christoph Engelbert
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & ToolsIan Barber
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 

Similar to Python Profiling Tools Optimize Code Performance (20)

Pygrunn 2012 down the rabbit - profiling in python
Pygrunn 2012   down the rabbit - profiling in pythonPygrunn 2012   down the rabbit - profiling in python
Pygrunn 2012 down the rabbit - profiling in python
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
NetConf 2018 BPF Observability
NetConf 2018 BPF ObservabilityNetConf 2018 BPF Observability
NetConf 2018 BPF Observability
 
MySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkMySQL Tokudb engine benchmark
MySQL Tokudb engine benchmark
 
How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]
 
Reutov, yunusov, nagibin random numbers take ii
Reutov, yunusov, nagibin   random numbers take iiReutov, yunusov, nagibin   random numbers take ii
Reutov, yunusov, nagibin random numbers take ii
 
Random numbers
Random numbersRandom numbers
Random numbers
 
Best Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesBest Practices in Handling Performance Issues
Best Practices in Handling Performance Issues
 
EKON22 Introduction to Machinelearning
EKON22 Introduction to MachinelearningEKON22 Introduction to Machinelearning
EKON22 Introduction to Machinelearning
 
Python update in 2018 #ll2018jp
Python update in 2018 #ll2018jpPython update in 2018 #ll2018jp
Python update in 2018 #ll2018jp
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
GoLang & GoatCore
GoLang & GoatCore GoLang & GoatCore
GoLang & GoatCore
 
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
 
Divolte Collector - meetup presentation
Divolte Collector - meetup presentationDivolte Collector - meetup presentation
Divolte Collector - meetup presentation
 
What I learned about IoT Security ... and why it's so hard!
What I learned about IoT Security ... and why it's so hard!What I learned about IoT Security ... and why it's so hard!
What I learned about IoT Security ... and why it's so hard!
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
Debugging Django
Debugging DjangoDebugging Django
Debugging Django
 
SOFA Tutorial
SOFA TutorialSOFA Tutorial
SOFA Tutorial
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 

Recently uploaded

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Python Profiling Tools Optimize Code Performance

  • 1. globo .com Profiling em Python Friday, October 4, 13
  • 2. porque profiling é importante? Friday, October 4, 13
  • 5. então vamos otimizar tudo! Friday, October 4, 13
  • 7. “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil” - Donald Knuth Friday, October 4, 13
  • 8. from timeit import timeit if __name__ == "__main__": setup = "from htmlmin.minify import html_minify;" setup += "from data import raw_html" t = timeit( stmt="html_minify(raw_html)", setup=setup, number=100) print(t) benchmark.py Friday, October 4, 13
  • 11. ‣ cProfile ‣ Profile ‣ hotshot (deprecated) ‣ trace ‣ line profiler ‣ memory profiler Friday, October 4, 13
  • 12. from data import raw_html from htmlmin.minify import html_minify if __name__ == "__main__": html_minify(raw_html) profile.py Friday, October 4, 13
  • 13. $ python -m cProfile profile.py Friday, October 4, 13
  • 24. $ python -m cProfile -o out profile.py Friday, October 4, 13
  • 25. $ python -m cProfile -o out profile.py Friday, October 4, 13
  • 26. >>> import pstats >>> p = pstats.Stats("out") >>> p.sort_stats("cumulative").print_stats(10) 315165 function calls (311828 primitive calls) in 1.334 seconds Ordered by: cumulative time List reduced from 675 to 10 due to restriction <10> ncalls tottime percall cumtime percall filename:lineno(function) 1 0.092 0.092 1.358 1.358 profile.py:2(<module>) 1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py: 7(<module>) 1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py: 17(<module>) 1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py: 1(<module>) 1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py: 2(<module>) 1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py: 12(<module>) 1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py: 26(html_minify) 2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py: 80(__init__) 2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py: 193(_feed) 2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py: 33(feed) Friday, October 4, 13
  • 27. >>> import pstats >>> p = pstats.Stats("out") >>> p.sort_stats("cumulative").print_stats(10) 315165 function calls (311828 primitive calls) in 1.334 seconds Ordered by: cumulative time List reduced from 675 to 10 due to restriction <10> ncalls tottime percall cumtime percall filename:lineno(function) 1 0.092 0.092 1.358 1.358 profile.py:2(<module>) 1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py: 7(<module>) 1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py: 17(<module>) 1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py: 1(<module>) 1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py: 2(<module>) 1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py: 12(<module>) 1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py: 26(html_minify) 2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py: 80(__init__) 2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py: 193(_feed) 2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py: 33(feed) Friday, October 4, 13
  • 28. >>> import pstats >>> p = pstats.Stats("out") >>> p.sort_stats("cumulative").print_stats(10) 315165 function calls (311828 primitive calls) in 1.334 seconds Ordered by: cumulative time List reduced from 675 to 10 due to restriction <10> ncalls tottime percall cumtime percall filename:lineno(function) 1 0.092 0.092 1.358 1.358 profile.py:2(<module>) 1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py: 7(<module>) 1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py: 17(<module>) 1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py: 1(<module>) 1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py: 2(<module>) 1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py: 12(<module>) 1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py: 26(html_minify) 2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py: 80(__init__) 2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py: 193(_feed) 2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py: 33(feed) Friday, October 4, 13
  • 29. >>> import pstats >>> p = pstats.Stats("out") >>> p.sort_stats("cumulative").print_stats(10) 315165 function calls (311828 primitive calls) in 1.334 seconds Ordered by: cumulative time List reduced from 675 to 10 due to restriction <10> ncalls tottime percall cumtime percall filename:lineno(function) 1 0.092 0.092 1.358 1.358 profile.py:2(<module>) 1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py: 7(<module>) 1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py: 17(<module>) 1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py: 1(<module>) 1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py: 2(<module>) 1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py: 12(<module>) 1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py: 26(html_minify) 2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py: 80(__init__) 2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py: 193(_feed) 2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py: 33(feed) Friday, October 4, 13
  • 30. >>> import pstats >>> p = pstats.Stats("out") >>> p.sort_stats("cumulative").print_stats(10) 315165 function calls (311828 primitive calls) in 1.334 seconds Ordered by: cumulative time List reduced from 675 to 10 due to restriction <10> ncalls tottime percall cumtime percall filename:lineno(function) 1 0.092 0.092 1.358 1.358 profile.py:2(<module>) 1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py: 7(<module>) 1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py: 17(<module>) 1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py: 1(<module>) 1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py: 2(<module>) 1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py: 12(<module>) 1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py: 26(html_minify) 2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py: 80(__init__) 2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py: 193(_feed) 2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py: 33(feed) Friday, October 4, 13
  • 31. >>> import pstats >>> p = pstats.Stats("out") >>> p.sort_stats("cumulative").print_stats(10) 315165 function calls (311828 primitive calls) in 1.334 seconds Ordered by: cumulative time List reduced from 675 to 10 due to restriction <10> ncalls tottime percall cumtime percall filename:lineno(function) 1 0.092 0.092 1.358 1.358 profile.py:2(<module>) 1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py: 7(<module>) 1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py: 17(<module>) 1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py: 1(<module>) 1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py: 2(<module>) 1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py: 12(<module>) 1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py: 26(html_minify) 2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py: 80(__init__) 2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py: 193(_feed) 2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py: 33(feed) Friday, October 4, 13
  • 32. >>> import pstats >>> p = pstats.Stats("out") >>> p.sort_stats("cumulative").print_stats(10) 315165 function calls (311828 primitive calls) in 1.334 seconds Ordered by: cumulative time List reduced from 675 to 10 due to restriction <10> ncalls tottime percall cumtime percall filename:lineno(function) 1 0.092 0.092 1.358 1.358 profile.py:2(<module>) 1 0.038 0.038 0.879 0.879 /(...)/htmlmin/minify.py: 7(<module>) 1 0.001 0.001 0.840 0.840 /(...)/bs4/__init__.py: 17(<module>) 1 0.073 0.073 0.839 0.839 /(...)/bs4/builder/__init__.py: 1(<module>) 1 0.027 0.027 0.511 0.511 /(...)/bs4/builder/_html5lib.py: 2(<module>) 1 0.028 0.028 0.483 0.483 /(...)/html5lib/__init__.py: 12(<module>) 1 0.001 0.001 0.387 0.387 /(...)/htmlmin/minify.py: 26(html_minify) 2 0.000 0.000 0.297 0.148 /(...)/bs4/__init__.py: 80(__init__) 2 0.000 0.000 0.296 0.148 /(...)/bs4/__init__.py: 193(_feed) 2 0.000 0.000 0.296 0.148 /(...)/bs4/builder/_html5lib.py: 33(feed) Friday, October 4, 13
  • 33. $ kernprof.py -l -v minify.py Friday, October 4, 13
  • 41. $ python -m memory_profiler minify.py Friday, October 4, 13
  • 50. outras ferramentas ‣ meliae ‣ heapy (guppy) ‣ benchy ‣ valgrind ‣ python object graphs (objgraph) ‣ plop ‣ pycounters Friday, October 4, 13
  • 53. algumas ferramentas ‣ django-debug-toolbar ‣ django-profiler ‣ new relic Friday, October 4, 13
  • 55. $ newrelic-admin run-program gunicorn -w 3 wsgi:application Friday, October 4, 13