<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>For what IT worths &#187; profiling</title>
	<atom:link href="http://www.forwhatitworths.com/posts/category/profiling/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.forwhatitworths.com</link>
	<description>taking I.T. personally</description>
	<lastBuildDate>Thu, 20 May 2010 23:30:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A performance patch</title>
		<link>http://www.forwhatitworths.com/posts/2007/10/a-performance-patch/</link>
		<comments>http://www.forwhatitworths.com/posts/2007/10/a-performance-patch/#comments</comments>
		<pubDate>Sun, 28 Oct 2007 12:34:41 +0000</pubDate>
		<dc:creator>tamasdecsi</dc:creator>
				<category><![CDATA[profiling]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.forwhatitworths.com/posts/2007/10/a-performance-patch/</guid>
		<description><![CDATA[Back in May 2006, I needed to performance-tune a web application built on Plone. The symptom was an unacceptable 60 seconds delay upon creating a new user account on top of the already existing 10000 accounts. The source of the delay was very soon traced back by Zope&#8217;s built-in call profiler to GroupUserFolder, where the [...]]]></description>
			<content:encoded><![CDATA[<p>Back in May 2006, I needed to performance-tune a web application built on Plone. The symptom was an unacceptable 60 seconds delay upon creating a new user account on top of the already existing 10000 accounts. The source of the delay was very soon traced back by Zope&#8217;s built-in call profiler to <a href="http://ingeniweb.sourceforge.net/Products/GroupUserFolder/">GroupUserFolder</a>, where the solution was instantly obvious.</p>
<p>The original method was checking for existing users by using linear list lookup, which is known to be algorithmically slower than dictionary key lookup. Knowing that, the performance patch was a no-brainer, and, as expected, it eliminated the reported delay. I&#8217;ve sent this patch to <a href="http://www.ingeniweb.com/">ingeniweb</a> (the author of GroupUserFolder) in an email on 22 May 2006, but haven&#8217;t heard back from them since. Yet, the patch has been accepted, even got refined a bit and <a href="http://dev.plone.org/collective/changeset?new=GroupUserFolder%2Ftrunk%2FGroupUserFolder.py%4024794&amp;old=GroupUserFolder%2Ftrunk%2FGroupUserFolder.py%4024784">was applied</a> on the code trunk on 13 Jun 2006. From the one side, I&#8217;m happy to see it at least being fixed, while on the other side, I could have been more happy receiving a feedback on my report.</p>
<p>Nevertheless, I was still wondering how exactly the two lookup methods compare, so I&#8217;ve put together a <a href="http://files.forwhatitworths.com/haskey_vs_inlist.py">python script</a> to check how much we can actually gain on using <code>haystack_dict.has_key(needle)</code> instead of <code>needle in haystack_list</code>. I&#8217;ve compared them with small to larger sample sizes in small to larger sets (and lists) of samples.</p>
<p>I&#8217;ve used <a href="http://www.starlink.ac.uk/topcat">TOPCAT</a>, an excellent, yet easy to use visualization tool for tabular data, to graphically represent the results.</p>
<p><img src="http://files.forwhatitworths.com/haskey_vs_inlist.gif" alt="has_key vs in list" /></p>
<p>As you can see, even at the small sets of small samples region, has_key performs much faster, and with the growing set and sample sizes, it keeps performing equally well, while list lookup goes wild in the same time.</p>
<p>Can&#8217;t say I was surprised or learned anything by doing this, but thought I&#8217;d mention as it might turn out to be useful for someone out there, so let me know if you&#8217;ve found this useful.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F&amp;title=A+performance+patch" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F&amp;title=A+performance+patch" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F&amp;title=A+performance+patch" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F&amp;title=A+performance+patch" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F&amp;title=A+performance+patch', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F&amp;title=A+performance+patch" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.forwhatitworths.com%2Fposts%2F2007%2F10%2Fa-performance-patch%2F&amp;title=A+performance+patch" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.forwhatitworths.com/posts/2007/10/a-performance-patch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
