4 ms·
There was a good blog post this by Armin. Basically, if you have to concatenate strings, don't do so via += but use "".join([]).
by Fede_V 12y ago
There was a good blog post this by Armin. Basically, if you have to concatenate strings, don't do so via += but use "".join([]).
- ant6n 12y agoI find that unexpected. Java has had string builder optimization for a long time, and CPython is much much faster in this respect. It's not always easy to use "".join when using a string, so you end up having to build a separate array of strings in some cases. And building arrays isn't always that fast either. And [].join doesn't exist, so summing arrays is always kinda slow. Anyway, all that is to say: I really like PyPy, and we use it a lot, but those _unexpected_ crazy slowdowns are unfortunate.