SlideShare a Scribd company logo
Why is Python
slow?
Daker Pinheiro
Why is CPython
slow?
Daker Pinheiro
Why is CPython
2.x slow?
Daker Pinheiro
$ whois dakerfp
Daker Fernandes Pinheiro
UFPE
INDT Recife
WebKit (Nix)
Qt, KDE, ...
C++, C, Python, Javascript, Prolog, ...
Pythonist since 2009
Is Python slow?
http://benchmarksgame.alioth.debian.org
Is Python slow?
http://benchmarksgame.alioth.debian.org
Is Python slow?
http://benchmarksgame.alioth.debian.org
Is Python slow?
http://benchmarksgame.alioth.debian.org
Is Python slow?
http://benchmarksgame.alioth.debian.org
Interpreted
Architecture independency
PyObject, PyObjectType &
PyHeapTypeObject
Typeless variables
Virtual Stack Machine
>>> (z * y) + x + z
Virtual Stack Machine
Bytecode Inspection
>>> import dis
>>> dis.dis(lambda x, y, z: (z * y) + x + z)
2 0 LOAD_FAST 2 (z)
3 LOAD_FAST 1 (y)
6 BINARY_MULTIPLY
7 LOAD_FAST 0 (x)
10 BINARY_ADD
11 LOAD_FAST 2 (z)
14 BINARY_ADD
15 RETURN_VALUE
100 * 100 * 100 * 100
vs
100 ** 4
dict()
vs
{}
Benchmark
>>> import timeit
>>> timeit.timeit("[i * i for i in xrange(100)]")
Concurrency
Global Interpreter Locker
Avoid Threads
Try Event Loops
Try Multiprocess
Know your Data Structures
Time Complexity
Use C/C++ Bindings
numpy
PyQt, PySide
...
standard library
[i * i for i in range(100)]]
[i * i for i in xrange(100)]]
[i * i for i in np.arange(100)]]
ar = np.arange(100); ar * ar
Memory
Python 3
Similar to Python 2.7 performance
Python 3 - Mailing list
Cython
cdef average(int a, int b):
return (a + b) / 2.0
Psyco
Dead, RIP
import psyco
psyco.full()
PyPy
http://speed.pypy.org/
Create C/C++ Bindings
Python.h
SIP
Boost.Python
Shiboken
Optimization Checklist
1. Legibillity
2. Architecture
3. Algorithm
4. Memory
5. Buffering
6. Caching
7. IO
8. Consider other languages :-(
Q & A
Daker Fernandes Pinheiro
http://codevereal.blogspot.com

More Related Content

What's hot (19)

PDF
Writing Fast Code - PyCon HK 2015
Younggun Kim
 
PDF
At the end of the rainbow
Ignacio Burgueño
 
PPTX
Python Applications
Kevin Cedeño, CISM, CISA
 
PDF
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
Pôle Systematic Paris-Region
 
PPTX
From Python to smartphones: neural nets @ Saint-Gobain, François Sausset
Pôle Systematic Paris-Region
 
PDF
Introduction to D programming language at Weka.IO
Liran Zvibel
 
PDF
Embedded. What Why How
Volodymyr Shymanskyy
 
PPTX
carrow - Go bindings to Apache Arrow via C++-API
Yoni Davidson
 
PDF
Startup Camp - Git, Python, Django session
Juraj Michálek
 
PDF
Git, Jenkins & Chuck
Juraj Michálek
 
PPTX
Pulumi. Modern Infrastructure as Code.
Yurii Bychenok
 
PDF
Metasepi team meeting #7: Snatch application on tiny OS
Kiwamu Okabe
 
PPTX
GDB: A Lot More Than You Knew
Undo
 
PDF
Use MQTT in Docker on Raspberry Pi
Philip Zheng
 
PDF
Run Go applications on Pico using TinyGo
Yu-Shuan Hsieh
 
PDF
The Parrot VM
François Perrad
 
PDF
Jython: Integrating Python and Java
Charles Anderson
 
PPT
Lua vs python
HoChul Shin
 
Writing Fast Code - PyCon HK 2015
Younggun Kim
 
At the end of the rainbow
Ignacio Burgueño
 
Python Applications
Kevin Cedeño, CISM, CISA
 
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
Pôle Systematic Paris-Region
 
From Python to smartphones: neural nets @ Saint-Gobain, François Sausset
Pôle Systematic Paris-Region
 
Introduction to D programming language at Weka.IO
Liran Zvibel
 
Embedded. What Why How
Volodymyr Shymanskyy
 
carrow - Go bindings to Apache Arrow via C++-API
Yoni Davidson
 
Startup Camp - Git, Python, Django session
Juraj Michálek
 
Git, Jenkins & Chuck
Juraj Michálek
 
Pulumi. Modern Infrastructure as Code.
Yurii Bychenok
 
Metasepi team meeting #7: Snatch application on tiny OS
Kiwamu Okabe
 
GDB: A Lot More Than You Knew
Undo
 
Use MQTT in Docker on Raspberry Pi
Philip Zheng
 
Run Go applications on Pico using TinyGo
Yu-Shuan Hsieh
 
The Parrot VM
François Perrad
 
Jython: Integrating Python and Java
Charles Anderson
 
Lua vs python
HoChul Shin
 

More from Daker Fernandes (8)

PDF
Functional Pattern Matching on Python
Daker Fernandes
 
PDF
Raspberry Pi + Python
Daker Fernandes
 
PDF
Opengl aula-01
Daker Fernandes
 
PDF
Jogos em Qt
Daker Fernandes
 
PDF
Dominando Modelos Ocultos de Markov com Python e GHMM
Daker Fernandes
 
PDF
CITi - PySide
Daker Fernandes
 
PDF
QtQuick - WSL II
Daker Fernandes
 
PDF
Mongodb workshop cinlug
Daker Fernandes
 
Functional Pattern Matching on Python
Daker Fernandes
 
Raspberry Pi + Python
Daker Fernandes
 
Opengl aula-01
Daker Fernandes
 
Jogos em Qt
Daker Fernandes
 
Dominando Modelos Ocultos de Markov com Python e GHMM
Daker Fernandes
 
CITi - PySide
Daker Fernandes
 
QtQuick - WSL II
Daker Fernandes
 
Mongodb workshop cinlug
Daker Fernandes
 
Ad

Recently uploaded (20)

PPTX
Using Google Data Studio (Looker Studio) to Create Effective and Easy Data Re...
Orage Technologies
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PDF
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
PDF
The Past, Present & Future of Kenya's Digital Transformation
Moses Kemibaro
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Using Google Data Studio (Looker Studio) to Create Effective and Easy Data Re...
Orage Technologies
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
The Past, Present & Future of Kenya's Digital Transformation
Moses Kemibaro
 
The Future of Artificial Intelligence (AI)
Mukul
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Ad

Why is Python slow? Python Nordeste 2013