A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-October/069225.html below:

Speed up + for string concatenation, now as fast as "".join(x) idiom

[Python-Dev] PATCH submitted: Speed up + for string concatenation, now as fast as "".join(x) idiom [Python-Dev] PATCH submitted: Speed up + for string concatenation, now as fast as "".join(x) idiomGregory P. Smith greg at electricrain.com
Thu Oct 5 21:28:58 CEST 2006
> I've never liked the "".join([]) idiom for string concatenation; in my 
> opinion it violates the principles "Beautiful is better than ugly." and 
> "There should be one-- and preferably only one --obvious way to do it.". 
> (And perhaps several others.)  To that end I've submitted patch #1569040 
> to SourceForge:
>     
> http://sourceforge.net/tracker/index.php?func=detail&aid=1569040&group_id=5470&atid=305470
> This patch speeds up using + for string concatenation.

yay!  i'm glad to see this.  i hate the "".join syntax.  i still write
that as string.join() because thats at least readable).  it also fixes
the python idiom for fast string concatenation as intended; anyone
whos ever written code that builds a large string value by pushing
substrings into a list only to call join later should agree.

mystr = "prefix"
while bla:
  #...
  mystr += moredata

is much nicer to read than

mystr = "prefix"
strParts = [mystr]
while bla:
  #...
  strParts.append(moredata)
mystr = "".join(strParts)

have you run any generic benchmarks such as pystone to get a better
idea of what the net effect on "typical" python code is?

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4