[BangPypers] Performance benefits of Generators?

Navin Kabra navin.kabra at gmail.com
Sat Jul 4 05:54:47 CEST 2009


> OTOH, Decorators , lambdas ('syntactic sugars') et al reduce the number of
> lines of code,
> depending on the scenario, for a given piece of complex logic, but these are
> 'slow'. But, I dont think
> the factor is huge enough to cause a performance bottleneck.  I had similar
> reservations on
> list comprehensions, but in some cases the bytecode generated by LC is same
> as the one generated
> by the if-else/loop counterparts. If you are building apps wherein  every
> microsecond matters,
> then it is better to time both variants - the sugars and their vanilla
> equivalents - and then choose the best.

I'm wondering: if you are building apps wherein every microsecond
matters, why are you doing it in Python? Python is bound to be about
10x slower than Java/C/C++ so for apps where performance is so
important, you're better off writing in those languages. Or, better
still, just replace the important parts with native C code. Python
code should focus on what python is good at - readability,
conciseness, maintainability. Leave the performance aspects to
languages that are better at it.

(Reference for the 10x slower comment -
http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/
- Dhananjay is also on this list, so maybe he will also jump in with a
response)

navin.


More information about the BangPypers mailing list