<?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"
	>
<channel>
	<title>Comments on: One line Ruby memoization</title>
	<atom:link href="http://unintelligible.org/blog/2007/08/16/one-line-ruby-memoization/feed/" rel="self" type="application/rss+xml" />
	<link>http://unintelligible.org/blog/2007/08/16/one-line-ruby-memoization/</link>
	<description></description>
	<pubDate>Fri, 05 Sep 2008 19:30:27 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Nick</title>
		<link>http://unintelligible.org/blog/2007/08/16/one-line-ruby-memoization/#comment-39</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Fri, 17 Aug 2007 19:27:13 +0000</pubDate>
		<guid isPermaLink="false">http://unintelligible.org/blog/2007/08/16/one-line-ruby-memoization/#comment-39</guid>
		<description>Much cleaner indeed. I think what I best liked about that technique was the idea of the method redefining itself, although it's obviously in need of a better application...</description>
		<content:encoded><![CDATA[<p>Much cleaner indeed. I think what I best liked about that technique was the idea of the method redefining itself, although it&#8217;s obviously in need of a better application&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shadowfiend</title>
		<link>http://unintelligible.org/blog/2007/08/16/one-line-ruby-memoization/#comment-38</link>
		<dc:creator>Shadowfiend</dc:creator>
		<pubDate>Fri, 17 Aug 2007 17:27:35 +0000</pubDate>
		<guid isPermaLink="false">http://unintelligible.org/blog/2007/08/16/one-line-ruby-memoization/#comment-38</guid>
		<description>It bears mentioning that the standard way of doing memoization in Ruby is using the &#124;&#124;= operator, and that seems to run much faster.

The code:

&lt;code&gt;class Memoized
  def memoized_method
    @result &#124;&#124;= lambda { puts 'computing expensive value'; sleep 2; 'hello world' }.call
  end
end&lt;/code&gt;

The timing:

&lt;code&gt;Rehearsal ------------------------------------
   0.040000   0.010000   0.050000 (  2.055683)
--------------------------- total: 0.050000sec

       user     system      total        real
   0.050000   0.010000   0.060000 (  0.055465)&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>It bears mentioning that the standard way of doing memoization in Ruby is using the ||= operator, and that seems to run much faster.</p>
<p>The code:</p>
<p><code>class Memoized<br />
  def memoized_method<br />
    @result ||= lambda { puts 'computing expensive value'; sleep 2; 'hello world' }.call<br />
  end<br />
end</code></p>
<p>The timing:</p>
<p><code>Rehearsal ------------------------------------<br />
   0.040000   0.010000   0.050000 (  2.055683)<br />
--------------------------- total: 0.050000sec</p>
<p>       user     system      total        real<br />
   0.050000   0.010000   0.060000 (  0.055465)</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
