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

"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
 
寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)
均民 戴
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
Jay Patel
 

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.sk
OneClick
 
2011 04 f1.sk
2011 04 f1.sk2011 04 f1.sk
2011 04 f1.sk
OneClick
 
2011 06 beauty.sk
2011 06 beauty.sk2011 06 beauty.sk
2011 06 beauty.sk
OneClick
 
2011 10 auto.sk
2011 10 auto.sk2011 10 auto.sk
2011 10 auto.sk
OneClick
 
2011 04 point network
2011 04 point network2011 04 point network
2011 04 point network
OneClick
 
2011 04 profutbal.sk
2011 04 profutbal.sk2011 04 profutbal.sk
2011 04 profutbal.sk
OneClick
 
JOB ANALYSIS AND HUMAN RESOURCE PLANNING
JOB ANALYSIS AND HUMAN RESOURCE PLANNINGJOB ANALYSIS AND HUMAN RESOURCE PLANNING
JOB ANALYSIS AND HUMAN RESOURCE PLANNING
Muhammad Farhan Javed
 
Innovative HRM Practices at IKEA
Innovative HRM Practices at IKEAInnovative HRM Practices at IKEA
Innovative HRM Practices at IKEA
Prasant Patro
 
Techniques for Forecasting Human Resources
Techniques  for Forecasting   Human ResourcesTechniques  for Forecasting   Human Resources
Techniques for Forecasting Human Resources
BHOMA RAM
 
Example of HRM Strategy - IKEA
Example of HRM Strategy - IKEAExample of HRM Strategy - IKEA
Example of HRM Strategy - IKEA
Mirna 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 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 python
Remco Wendt
 
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
DefconRussia
 
GoLang & GoatCore
GoLang & GoatCore GoLang & GoatCore
GoLang & GoatCore
Sebastian Pożoga
 

Similar to 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
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
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
 
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
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 

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