
March 30, 2020
10:08 p.m.
On Tue, Mar 31, 2020 at 03:01:51PM +1100, Steven D'Aprano wrote:
nor the fastest way
It's pretty close though.
On my test, accumulating 500,000 strings into a list versus a StringIO buffer, then building a string, took 27.5 versus 31.6 ms. Using a string took 36.4 ms. So it's faster than the optimized string concat, and within arm's reach of list+join.
I re-ran the test with a single non-ASCII character added to the very end, '\U0001D400'. Both the list and the StringIO versions slowed down by about the same amount of time (approx 4ms) so the difference between them remained the same in absolute terms but shrank marginally in relative terms. YMMV. -- Steven