<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Speed up Python without effort using generator expressions</title>
	<atom:link href="http://lemire.me/blog/archives/2008/09/05/speed-up-python-without-effort-using-generator-expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://lemire.me/blog/archives/2008/09/05/speed-up-python-without-effort-using-generator-expressions/</link>
	<description>Computer Scientist and Open Scholar: Databases, Information Retrieval, Business Intelligence.</description>
	<lastBuildDate>Thu, 09 Feb 2012 11:13:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Daniel Lemire</title>
		<link>http://lemire.me/blog/archives/2008/09/05/speed-up-python-without-effort-using-generator-expressions/comment-page-1/#comment-50157</link>
		<dc:creator>Daniel Lemire</dc:creator>
		<pubDate>Fri, 19 Sep 2008 15:53:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.daniel-lemire.com/blog/?p=1268#comment-50157</guid>
		<description>Running code through cProfile is not fair since it adds an overhead for each function call.

Run these commands instead:

echo &quot;sum([x for x in xrange(1000000)])&quot; &gt; t1.py

echo &quot;sum((x for x in xrange(1000000)))&quot; &gt; t2.py

python t1.py

python t2.py</description>
		<content:encoded><![CDATA[<p>Running code through cProfile is not fair since it adds an overhead for each function call.</p>
<p>Run these commands instead:</p>
<p>echo &#8220;sum([x for x in xrange(1000000)])&#8221; > t1.py</p>
<p>echo &#8220;sum((x for x in xrange(1000000)))&#8221; > t2.py</p>
<p>python t1.py</p>
<p>python t2.py</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andres</title>
		<link>http://lemire.me/blog/archives/2008/09/05/speed-up-python-without-effort-using-generator-expressions/comment-page-1/#comment-50156</link>
		<dc:creator>Andres</dc:creator>
		<pubDate>Fri, 19 Sep 2008 14:47:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.daniel-lemire.com/blog/?p=1268#comment-50156</guid>
		<description>Hi Daniel! 
Reading this post I try myself to do it. The results were not the same as you, I post it here. I work on python and I think that is correct that this happens, because generators in some operations are more expensive that simple list. when you have to read a big file generators are the solution, but in other cases lists are the solution!

cProfile.run(&#039;sum((x for x in xrange(1000000)))&#039;)
         1000004 function calls in 1.305 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  1000001    0.565    0.000    0.565    0.000 :1()
        1    0.000    0.000    1.305    1.305 :1()
        1    0.000    0.000    0.000    0.000 {method &#039;disable&#039; of &#039;_lsprof.Profiler&#039; objects}
        1    0.740    0.740    1.305    1.305 {sum}


cProfile.run(&#039;sum([x for x in xrange(1000000)])&#039;)
         3 function calls in 0.540 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.357    0.357    0.540    0.540 :1()
        1    0.000    0.000    0.000    0.000 {method &#039;disable&#039; of &#039;_lsprof.Profiler&#039; objects}
        1    0.182    0.182    0.182    0.182 {sum}</description>
		<content:encoded><![CDATA[<p>Hi Daniel!<br />
Reading this post I try myself to do it. The results were not the same as you, I post it here. I work on python and I think that is correct that this happens, because generators in some operations are more expensive that simple list. when you have to read a big file generators are the solution, but in other cases lists are the solution!</p>
<p>cProfile.run(&#8216;sum((x for x in xrange(1000000)))&#8217;)<br />
         1000004 function calls in 1.305 CPU seconds</p>
<p>   Ordered by: standard name</p>
<p>   ncalls  tottime  percall  cumtime  percall filename:lineno(function)<br />
  1000001    0.565    0.000    0.565    0.000 :1()<br />
        1    0.000    0.000    1.305    1.305 :1()<br />
        1    0.000    0.000    0.000    0.000 {method &#8216;disable&#8217; of &#8216;_lsprof.Profiler&#8217; objects}<br />
        1    0.740    0.740    1.305    1.305 {sum}</p>
<p>cProfile.run(&#8216;sum([x for x in xrange(1000000)])&#8217;)<br />
         3 function calls in 0.540 CPU seconds</p>
<p>   Ordered by: standard name</p>
<p>   ncalls  tottime  percall  cumtime  percall filename:lineno(function)<br />
        1    0.357    0.357    0.540    0.540 :1()<br />
        1    0.000    0.000    0.000    0.000 {method &#8216;disable&#8217; of &#8216;_lsprof.Profiler&#8217; objects}<br />
        1    0.182    0.182    0.182    0.182 {sum}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos</title>
		<link>http://lemire.me/blog/archives/2008/09/05/speed-up-python-without-effort-using-generator-expressions/comment-page-1/#comment-50129</link>
		<dc:creator>Carlos</dc:creator>
		<pubDate>Fri, 05 Sep 2008 16:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.daniel-lemire.com/blog/?p=1268#comment-50129</guid>
		<description>Not only that, but expression 2 doesn&#039;t leak a variable!

$ python 
Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; i
Traceback (most recent call last):
  File &quot;&quot;, line 1, in 
NameError: name &#039;i&#039; is not defined
&gt;&gt;&gt; sum([i for i in xrange(100000)])
4999950000L
&gt;&gt;&gt; i
99999
&gt;&gt;&gt; sum(j for j in xrange(100000))
4999950000L
&gt;&gt;&gt; j
Traceback (most recent call last):
  File &quot;&quot;, line 1, in 
NameError: name &#039;j&#039; is not defined
&gt;&gt;&gt;</description>
		<content:encoded><![CDATA[<p>Not only that, but expression 2 doesn&#8217;t leak a variable!</p>
<p>$ python<br />
Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)<br />
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin<br />
Type &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information.<br />
&gt;&gt;&gt; i<br />
Traceback (most recent call last):<br />
  File &#8220;&#8221;, line 1, in<br />
NameError: name &#8216;i&#8217; is not defined<br />
&gt;&gt;&gt; sum([i for i in xrange(100000)])<br />
4999950000L<br />
&gt;&gt;&gt; i<br />
99999<br />
&gt;&gt;&gt; sum(j for j in xrange(100000))<br />
4999950000L<br />
&gt;&gt;&gt; j<br />
Traceback (most recent call last):<br />
  File &#8220;&#8221;, line 1, in<br />
NameError: name &#8216;j&#8217; is not defined<br />
&gt;&gt;&gt;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

