4 ms·
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
by rix0r 16y ago
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.
- RiderOfGiraffes 16y ago> 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?
- StavrosK 16y agoYeah, 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.
- Nitramp 16y agoIndeed 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?