Tutorials on optimizing non-trivial Python applications with C extensions or Cython -


the python community has published helpful reference material showing how profile python code, , technical details of python extensions in c or in cython. still searching tutorials show, however, non-trivial python programs, following:

  1. how identify hotspots benefit optimization conversion c extension
  2. just importantly, how identify hotspots not benefit conversion c extension
  3. finally, how make appropriate conversion python c, either using python c-api or (perhaps preferably) using cython.

a tutorial provide reader methodology on how reason through problem of optimization working through complete example. have had no success finding such resource.

do know of (or have written) such tutorial?

for clarification, i'm not interested in tutorials cover only following:

  • using (c)profile profile python code measure running times
  • using tools examine profiles (i recommend runsnakerun)
  • optimizing selecting more appropriate algorithms or python constructs (e.g., sets membership tests instead of lists); tutorial should assume algorithm , python code optimal, , @ point c extension next logical step
  • recapitulating python documentation on writing c extensions, excellent reference not useful resource showing when , how move python c.

points 1 , 2 basic optimization rule of thumbs. astonished if there anywhere kind of tutorial looking for. maybe that's why haven't found one. short list:

  • rule number 1 of optimization don't.
  • rule number 2 measure
  • rule number 3 identify limiting factor (if it's io or database bound, no optimization may reachable anyway).
  • rule number 4 think, use better algorithms , data structure ...
  • considering change of language quite low on list...

just start profiling python code usual python tools. find code need optimized. try optimize sticking python. if still slow, try understand why. if it's io bound unlikely c program better. if problem come algorithm unlikely c perform better. "good" cases c quite rare, runtime should not far away want (like 2 of 3 times speedup) data structure simples , benefit low level representation , really, need speedup. in other cases using c instead of python unrewarding job.

really quite rare calling c code python done performance in mind primary goal. more goal interface python existing c code.

and other poster said, better advised of using cython.

if still want write c module python, necessary in official documentation.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -