<?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: JavaScript Memoization</title>
	<atom:link href="http://readystate4.com/2009/02/25/javascript-memoization/feed/" rel="self" type="application/rss+xml" />
	<link>http://readystate4.com/2009/02/25/javascript-memoization/</link>
	<description>JavaScript, Web Development, Ruby, and Technology.</description>
	<lastBuildDate>Sun, 06 Jun 2010 14:40:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dan Bjorge</title>
		<link>http://readystate4.com/2009/02/25/javascript-memoization/comment-page-1/#comment-938</link>
		<dc:creator>Dan Bjorge</dc:creator>
		<pubDate>Wed, 17 Jun 2009 17:44:38 +0000</pubDate>
		<guid isPermaLink="false">http://readystate4.com/2009/02/25/javascript-memoization/#comment-938</guid>
		<description>That code does not test what you seem to think it tests. memoized does NOT do the same thing as plain in a much more efficient way - memoized returns a NEW FUNCTION which does the same thing as plain. To use the function as intended, you&#039;d want to use this for your bottom loop:

m = memoized();
for(var i=0; i&lt;5000; i++) {
    m();
}

When you try it with just that modification, you will probably find that it does much WORSE than plain on its own, but that too is not strictly correct because your test methodology is terrible - most browsers have a harder time with 5001 elements than 1 element, so you&#039;ll usually find that even if you were using plain() in both of those loops, it would take much longer the second time through.

If you run the tests separately, such that they WON&#039;T interfere with each other, you&#039;ll find that the results are about the same timing - memoization is a useful technique when you&#039;re trying to only perform an intensive computation once instead of over and over, but the intensive part of plain() is inserting things into DOM structures, not a javascript lookup two objects deep. You&#039;re not actually memoizing the hard part of the function, since for that particular function it wouldn&#039;t make any sense to do so.</description>
		<content:encoded><![CDATA[<p>That code does not test what you seem to think it tests. memoized does NOT do the same thing as plain in a much more efficient way &#8211; memoized returns a NEW FUNCTION which does the same thing as plain. To use the function as intended, you&#8217;d want to use this for your bottom loop:</p>
<p>m = memoized();<br />
for(var i=0; i&lt;5000; i++) {<br />
    m();<br />
}</p>
<p>When you try it with just that modification, you will probably find that it does much WORSE than plain on its own, but that too is not strictly correct because your test methodology is terrible &#8211; most browsers have a harder time with 5001 elements than 1 element, so you&#8217;ll usually find that even if you were using plain() in both of those loops, it would take much longer the second time through.</p>
<p>If you run the tests separately, such that they WON&#8217;T interfere with each other, you&#8217;ll find that the results are about the same timing &#8211; memoization is a useful technique when you&#8217;re trying to only perform an intensive computation once instead of over and over, but the intensive part of plain() is inserting things into DOM structures, not a javascript lookup two objects deep. You&#8217;re not actually memoizing the hard part of the function, since for that particular function it wouldn&#8217;t make any sense to do so.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
