SlideShare ist ein Scribd-Unternehmen logo
1 von 58
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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ć
 

Andere mochten auch (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
 

Ähnlich wie Profiling em Python

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
 

Ähnlich wie Profiling em Python (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
 

Kürzlich hochgeladen

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Kürzlich hochgeladen (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Profiling em Python

  • 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