Why is Python slow? Python Nordeste 2013

3,999 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,999
On SlideShare
0
From Embeds
0
Number of Embeds
2,586
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Why is Python slow? Python Nordeste 2013

  1. 1. Why is Pythonslow?Daker Pinheiro
  2. 2. Why is CPythonslow?Daker Pinheiro
  3. 3. Why is CPython2.x slow?Daker Pinheiro
  4. 4. $ whois dakerfpDaker Fernandes PinheiroUFPEINDT RecifeWebKit (Nix)Qt, KDE, ...C++, C, Python, Javascript, Prolog, ...Pythonist since 2009
  5. 5. Is Python slow?http://benchmarksgame.alioth.debian.org
  6. 6. Is Python slow?http://benchmarksgame.alioth.debian.org
  7. 7. Is Python slow?http://benchmarksgame.alioth.debian.org
  8. 8. Is Python slow?http://benchmarksgame.alioth.debian.org
  9. 9. Is Python slow?http://benchmarksgame.alioth.debian.org
  10. 10. InterpretedArchitecture independency
  11. 11. PyObject, PyObjectType &PyHeapTypeObject
  12. 12. Typeless variables
  13. 13. Virtual Stack Machine>>> (z * y) + x + z
  14. 14. Virtual Stack Machine
  15. 15. 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_MULTIPLY7 LOAD_FAST 0 (x)10 BINARY_ADD11 LOAD_FAST 2 (z)14 BINARY_ADD15 RETURN_VALUE
  16. 16. 100 * 100 * 100 * 100vs100 ** 4
  17. 17. dict()vs{}
  18. 18. Benchmark>>> import timeit>>> timeit.timeit("[i * i for i in xrange(100)]")
  19. 19. ConcurrencyGlobal Interpreter LockerAvoid ThreadsTry Event LoopsTry Multiprocess
  20. 20. Know your Data StructuresTime Complexity
  21. 21. Use C/C++ BindingsnumpyPyQt, PySide...standard library
  22. 22. [i * i for i in range(100)]][i * i for i in xrange(100)]][i * i for i in np.arange(100)]]
  23. 23. ar = np.arange(100); ar * ar
  24. 24. Memory
  25. 25. Python 3Similar to Python 2.7 performancePython 3 - Mailing list
  26. 26. Cythoncdef average(int a, int b):return (a + b) / 2.0
  27. 27. PsycoDead, RIPimport psycopsyco.full()
  28. 28. PyPyhttp://speed.pypy.org/
  29. 29. Create C/C++ BindingsPython.hSIPBoost.PythonShiboken
  30. 30. Optimization Checklist1. Legibillity2. Architecture3. Algorithm4. Memory5. Buffering6. Caching7. IO8. Consider other languages :-(
  31. 31. Q & ADaker Fernandes Pinheirohttp://codevereal.blogspot.com

×