News for hackers. Stuff that matters.
Re:Python Patterns - An Optimization Anecdote by rix0r on Tuesday November 02, 2010 @04:09AM (#1859636)
The first thing that stuck out to me like a sore thumb was the string-concatenation-in-a-loop. Though the author was aware of its consequences he only addressed it late in the article, optimizing relatively trivial stuff like variable lookups first. And then he did so in a rather strange way, instead of adding string fragments to a list and then join()ing them.

Not sure how fast that loop would be in Python compared to the implied loop&join but I sure would have liked to see them compared.

Re:Python Patterns - An Optimization Anecdote by RiderOfGiraffes on Tuesday November 02, 2010 @04:31AM (#1859670)

  > Not sure how fast that loop would be in Python
  > compared to the implied loop&join but I sure
  > would have liked to see them compared.
Why don't you try it and tell us the results?
Re:Python Patterns - An Optimization Anecdote by StavrosK on Tuesday November 02, 2010 @06:19AM (#1859800)
Yeah, seriously. "".join((chr(x) for x in chars)) would be the first thing I did (I'm not sure if comprehensions are faster than generators, they probably are, so I'd test for that as well.
Re:Python Patterns - An Optimization Anecdote by Nitramp on Tuesday November 02, 2010 @09:51AM (#1860380)
Indeed seems strange to micro optimize all that stuff without first fixing the obvious quadratic runtime part.

By the way, is there no mutable string object (à la Java's StringBuilder/Buffer) in Python?