<?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>TK Studios &#187; optimization</title>
	<atom:link href="http://www.tkstudios.com/tag/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tkstudios.com</link>
	<description>Web Application Design &#38; Development</description>
	<lastBuildDate>Mon, 20 Jun 2011 16:07:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quick JS experiment: Function Overhead</title>
		<link>http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/</link>
		<comments>http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 17:27:44 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[FOR SCIENCE]]></category>
		<category><![CDATA[micro-optimization]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=241</guid>
		<description><![CDATA[Probably common knowledge, but I just slapped together a quick test script to determine what kind of overhead there is between a) writing a function inline, b) keeping the function as part of an object (say, utility.isObject), and c) same as b, but get a reference to the function first. Each approach was iterated a [...]]]></description>
			<content:encoded><![CDATA[<p>Probably common knowledge, but I just slapped together a quick test script to determine what kind of overhead there is between a) writing a function inline, b) keeping the function as part of an object (say, utility.isObject), and c) same as b, but get a reference to the function first. Each approach was iterated a total of <em>100,000,000 times</em> to get usable time values. Tests were performed in Chrome 7, so YMMV. <span id="more-241"></span></p>
<p><strong>Results:</strong></p>
<p><strong>A:</strong> typeof obj == &#8220;object&#8221; : <strong>439 msec</strong><br />
<strong>B:</strong> util.isObj(obj) : <strong>1228 msec</strong> <em>(where util = { isObj : function(o) { return typeof o == &#8220;object&#8221;; } }) </em><br />
<strong>C:</strong> isObj(obj) : <strong>1155 msec</strong> <em>(where B and isObj = util.isObj)</em></p>
<p><strong>Conclusions: </strong></p>
<p>First, remember that these are looping over <strong>100 million</strong> iterations. This kind of research might be useful for a worker thread, but it&#8217;s not terribly useful for day to day stuff.</p>
<p>The big conclusion here is if you&#8217;re only going to call a function from one or two places, or it&#8217;s very short, skipping the function and putting the code inline will save you about 60%, but it&#8217;s really only significant if you&#8217;re calling that function millions of times.</p>
<p>The second conclusion is that if you must use a function for something like this (millions of calls), you can save a tiny bit—almost completely insignificant—of time by getting a reference to that function. Keep in mind that this micro-optimization<em> only works if the function you&#8217;re calling doesn&#8217;t require context</em>. If you have to use the <em>.call</em> or <em>.apply</em> methods to add context, this approach is actually about <strong>17x slower</strong>.</p>
<p>Actual testing code at <a href="http://jsfiddle.net/jsylvanus/tTsXp/">http://jsfiddle.net/jsylvanus/tTsXp/</a></p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Quick+JS+experiment%3A+Function+Overhead+http%3A%2F%2Fis.gd%2FqQRGRd+%28%40tkstudios%29" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=Quick+JS+experiment%3A+Function+Overhead+http%3A%2F%2Fis.gd%2FqQRGRd+%28%40tkstudios%29" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/&amp;title=Quick+JS+experiment%3A+Function+Overhead" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/&amp;title=Quick+JS+experiment%3A+Function+Overhead" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/&amp;title=Quick+JS+experiment%3A+Function+Overhead" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/&amp;title=Quick+JS+experiment%3A+Function+Overhead" title="Post to Reddit">Post to Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/&amp;title=Quick+JS+experiment%3A+Function+Overhead" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/&amp;title=Quick+JS+experiment%3A+Function+Overhead" title="Post to StumbleUpon">Stumble This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2010/11/03/quick-js-experiment-function-overhead/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP hashing performance experiment</title>
		<link>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/</link>
		<comments>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 05:26:52 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Listy]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=150</guid>
		<description><![CDATA[Today, in the never-ending quest to tweak server performance by a few milliseconds, I decided to do a bit of testing of various php hashing methods. I therefore wrote a quick script under php (5.2.11 currently, I need to update), which ran each test case 10,000 times to achieve a decent min/avg/max for each case, [...]]]></description>
			<content:encoded><![CDATA[<p>Today, in the never-ending quest to tweak server performance by a few milliseconds, I decided to do a bit of testing of various php hashing methods. I therefore wrote a quick script under php (5.2.11 currently, I need to update), which ran each test case 10,000 times to achieve a decent min/avg/max for each case, on strings of 10KB, 100KB, and 1,000KB in size.</p>
<p><span id="more-150"></span></p>
<p>The short version of the result is that the md5() function won across the board. The comments in the <a title="PHP: hash - Manual" href="http://us.php.net/manual/en/function.hash.php">php.net hash function documentation</a> seemed to indicate a performance increase in using hash(&#8216;md5&#8242;,$str), and an even better increase in hash(&#8216;md4&#8242;,$str). I found this to only partially be the case; While using the hash function, md4 is minutely faster than md5, the md5() function itself is considerably faster than either of these.</p>
<p>So, for any performance sensitive case, I would say md5() is by far the best choice.</p>
<p>Actual results of the test suite can be seen here:</p>
<p><a href="http://listy.us/list/view/153"><img src="http://www.listy.us/list/banner/153" alt="PHP Hash Performance by JSylvanus via Listy.us" /></a></p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=PHP+hashing+performance+experiment+http%3A%2F%2Fis.gd%2FHclqbV+%28%40tkstudios%29" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=PHP+hashing+performance+experiment+http%3A%2F%2Fis.gd%2FHclqbV+%28%40tkstudios%29" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Reddit">Post to Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to StumbleUpon">Stumble This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

