Top Banner
Why is Python slow? Daker Pinheiro
31

Why is Python slow? Python Nordeste 2013

May 06, 2015

Download

Technology

Daker Fernandes
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Why is Python slow? Python Nordeste 2013

Why is Pythonslow?Daker Pinheiro

Page 2: Why is Python slow? Python Nordeste 2013

Why is CPythonslow?Daker Pinheiro

Page 3: Why is Python slow? Python Nordeste 2013

Why is CPython2.x slow?

Daker Pinheiro

Page 4: Why is Python slow? Python Nordeste 2013

$ whois dakerfpDaker Fernandes Pinheiro

UFPEINDT RecifeWebKit (Nix)Qt, KDE, ...C++, C, Python, Javascript, Prolog, ...Pythonist since 2009

Page 5: Why is Python slow? Python Nordeste 2013

Is Python slow?

http://benchmarksgame.alioth.debian.org

Page 6: Why is Python slow? Python Nordeste 2013

Is Python slow?

http://benchmarksgame.alioth.debian.org

Page 7: Why is Python slow? Python Nordeste 2013

Is Python slow?

http://benchmarksgame.alioth.debian.org

Page 8: Why is Python slow? Python Nordeste 2013

Is Python slow?

http://benchmarksgame.alioth.debian.org

Page 9: Why is Python slow? Python Nordeste 2013

Is Python slow?

http://benchmarksgame.alioth.debian.org

Page 10: Why is Python slow? Python Nordeste 2013

InterpretedArchitecture independency

Page 11: Why is Python slow? Python Nordeste 2013

PyObject, PyObjectType &PyHeapTypeObject

Page 12: Why is Python slow? Python Nordeste 2013

Typeless variables

Page 13: Why is Python slow? Python Nordeste 2013

Virtual Stack Machine>>> (z * y) + x + z

Page 14: Why is Python slow? Python Nordeste 2013

Virtual Stack Machine

Page 15: Why is Python slow? Python Nordeste 2013

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

Page 16: Why is Python slow? Python Nordeste 2013

100 * 100 * 100 * 100vs

100 ** 4

Page 17: Why is Python slow? Python Nordeste 2013

dict()vs{}

Page 18: Why is Python slow? Python Nordeste 2013

Benchmark>>> import timeit>>> timeit.timeit("[i * i for i in xrange(100)]")

Page 19: Why is Python slow? Python Nordeste 2013

ConcurrencyGlobal Interpreter LockerAvoid ThreadsTry Event LoopsTry Multiprocess

Page 20: Why is Python slow? Python Nordeste 2013

Know your Data StructuresTime Complexity

Page 21: Why is Python slow? Python Nordeste 2013

Use C/C++ BindingsnumpyPyQt, PySide...standard library

Page 22: Why is Python slow? Python Nordeste 2013

[i * i for i in range(100)]][i * i for i in xrange(100)]]

[i * i for i in np.arange(100)]]

Page 23: Why is Python slow? Python Nordeste 2013

ar = np.arange(100); ar * ar

Page 24: Why is Python slow? Python Nordeste 2013

Memory

Page 25: Why is Python slow? Python Nordeste 2013

Python 3Similar to Python 2.7 performance

Python 3 - Mailing list

Page 26: Why is Python slow? Python Nordeste 2013

Cythoncdef average(int a, int b): return (a + b) / 2.0

Page 27: Why is Python slow? Python Nordeste 2013

Psyco

Dead, RIP

import psycopsyco.full()

Page 28: Why is Python slow? Python Nordeste 2013

PyPy

http://speed.pypy.org/

Page 29: Why is Python slow? Python Nordeste 2013

Create C/C++ BindingsPython.hSIPBoost.PythonShiboken

Page 30: Why is Python slow? Python Nordeste 2013

Optimization Checklist1. Legibillity2. Architecture3. Algorithm4. Memory5. Buffering6. Caching7. IO8. Consider other languages :-(

Page 31: Why is Python slow? Python Nordeste 2013

Q & ADaker Fernandes Pinheiro

http://codevereal.blogspot.com