Wow thanks for the quick response.  The performance is *much, much* better with the suggested list-join.  CPython still beats Pypy, but only by a narrow margin:<div><br></div><div><font face="&#39;courier new&#39;, monospace">pypy1.6:             1m33.142s</font></div>

<div><font face="&#39;courier new&#39;, monospace">CPython 2.7.1:       1m12.092s</font></div><div><br></div><div>Thanks for the advice-- I had forgotten about string immutability and its associated costs.  And keep up the good work on pypy!  I look forward to the day I can replace CPython with pypy in more interesting scientific workflows &lt;/end plug for scipy integration&gt;</div>

<div><br></div><div>A bit OT:  The recent release of ipython added some powerful multiprocessing features using ZeroMQ.  I&#39;ve only glanced at pypy&#39;s extensive threading optimizations (e.g., greenlets).  Does pypy jit across thread/process boundaries?</div>

<div>--<br>Jake Biesinger<br>Graduate Student<br>Xie Lab, UC Irvine<br>
<br><br><div class="gmail_quote">On Thu, Aug 18, 2011 at 4:01 PM, Justin Peel <span dir="ltr">&lt;<a href="mailto:peelpy@gmail.com">peelpy@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Yes, I just looked at it. For cases like this where there is<br>
effectively only one reference to the string being appended to, it<br>
just resizes the string in-place and copies in the string being<br>
appended which gives it O(N) performance. It is a hack that is<br>
available only because of the reference counting that CPython employs<br>
for memory management.<br>
<br>
For reference, the hack is in Python/ceval.c in the string_concatenate function.<br>
<div><div></div><div class="h5"><br>
On Thu, Aug 18, 2011 at 4:50 PM, Aaron DeVore &lt;<a href="mailto:aaron.devore@gmail.com">aaron.devore@gmail.com</a>&gt; wrote:<br>
&gt; Python 2.4 introduced a change that helps improve performance of<br>
&gt; string concatenation, according to its release notes. I don&#39;t know<br>
&gt; anything beyond that.<br>
&gt;<br>
&gt; -Aaron DeVore<br>
&gt;<br>
&gt; On Thu, Aug 18, 2011 at 3:31 PM, Justin Peel &lt;<a href="mailto:peelpy@gmail.com">peelpy@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Yes, Vincent&#39;s way is the better way to go. To elaborate more on the<br>
&gt;&gt; problem, string appending is O(N^2) while appending to a list and then<br>
&gt;&gt; joining is an O(N) operation. Why CPython is faster than Pypy at doing<br>
&gt;&gt; the less efficient way is something that I&#39;m not fully sure about, but<br>
&gt;&gt; I believe that it might have to do with the differing memory<br>
&gt;&gt; management strategies.<br>
&gt;&gt;<br>
&gt;&gt; On Thu, Aug 18, 2011 at 4:24 PM, Vincent Legoll<br>
&gt;&gt; &lt;<a href="mailto:vincent.legoll@gmail.com">vincent.legoll@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; Hello,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Try this:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; import sys<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; fasta_file = sys.argv[1]  # should be *.fa<br>
&gt;&gt;&gt; print &#39;loading dna from&#39;, fasta_file<br>
&gt;&gt;&gt; chroms = {}<br>
&gt;&gt;&gt; dna = []<br>
&gt;&gt;&gt; for l in open(fasta_file):<br>
&gt;&gt;&gt;    if l.startswith(&#39;&gt;&#39;):  # new chromosome<br>
&gt;&gt;&gt;        if len(dna) &gt; 0:<br>
&gt;&gt;&gt;            chroms[chrom] = &#39;&#39;.join(dna)<br>
&gt;&gt;&gt;        chrom = l.strip().replace(&#39;&gt;&#39;, &#39;&#39;)<br>
&gt;&gt;&gt;        dna = []<br>
&gt;&gt;&gt;    else:<br>
&gt;&gt;&gt;        dna.append(l.rstrip())<br>
&gt;&gt;&gt; if len(dna) &gt; 0:<br>
&gt;&gt;&gt;    chroms[chrom] = &#39;&#39;.join(dna)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; --<br>
&gt;&gt;&gt; Vincent Legoll<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; pypy-dev mailing list<br>
&gt;&gt;&gt; <a href="mailto:pypy-dev@python.org">pypy-dev@python.org</a><br>
&gt;&gt;&gt; <a href="http://mail.python.org/mailman/listinfo/pypy-dev" target="_blank">http://mail.python.org/mailman/listinfo/pypy-dev</a><br>
&gt;&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; pypy-dev mailing list<br>
&gt;&gt; <a href="mailto:pypy-dev@python.org">pypy-dev@python.org</a><br>
&gt;&gt; <a href="http://mail.python.org/mailman/listinfo/pypy-dev" target="_blank">http://mail.python.org/mailman/listinfo/pypy-dev</a><br>
&gt;&gt;<br>
&gt;<br>
_______________________________________________<br>
pypy-dev mailing list<br>
<a href="mailto:pypy-dev@python.org">pypy-dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/pypy-dev" target="_blank">http://mail.python.org/mailman/listinfo/pypy-dev</a><br>
</div></div></blockquote></div><br></div>