<?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: Ruby TMTOWTDI, Episode 1</title>
	<atom:link href="http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/</link>
	<description>CitrusByte</description>
	<pubDate>Fri, 21 Nov 2008 10:11:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: zdk</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-31</link>
		<dc:creator>zdk</dc:creator>
		<pubDate>Thu, 26 Jun 2008 16:23:01 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-31</guid>
		<description>h = Hash.new;str.each(' ') { &#124;s&#124; h[s[0,1]] = s[1,3].to_i }

just wondering what about this?</description>
		<content:encoded><![CDATA[<p>h = Hash.new;str.each(&#8217; &#8216;) { |s| h[s[0,1]] = s[1,3].to_i }</p>
<p>just wondering what about this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Koontz</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-28</link>
		<dc:creator>David Koontz</dc:creator>
		<pubDate>Thu, 05 Jun 2008 16:23:01 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-28</guid>
		<description>My (without looking) solution was pretty similar to Nick's although I didn't assume the key would always be a single character.

str.split.inject({}) {&#124;hash, item&#124; item =~ /(\w+?)(\d+)/; hash[$1] = $2.to_i; hash}

Something strange I noticed was the parentheses around two of the block parameters in Nick's solution. I removed them and to my surprise it had a drastic impact on performance.

With parentheses: 6.66 Without parentheses: 8.45

I got similar result with JRuby. Can anyone explain what the presence of parentheses in the argument list even does and how that might be impacting performance?</description>
		<content:encoded><![CDATA[<p>My (without looking) solution was pretty similar to Nick&#8217;s although I didn&#8217;t assume the key would always be a single character.</p>
<p>str.split.inject({}) {|hash, item| item =~ /(\w+?)(\d+)/; hash[$1] = $2.to_i; hash}</p>
<p>Something strange I noticed was the parentheses around two of the block parameters in Nick&#8217;s solution. I removed them and to my surprise it had a drastic impact on performance.</p>
<p>With parentheses: 6.66 Without parentheses: 8.45</p>
<p>I got similar result with JRuby. Can anyone explain what the presence of parentheses in the argument list even does and how that might be impacting performance?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat Nakajima</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-29</link>
		<dc:creator>Pat Nakajima</dc:creator>
		<pubDate>Thu, 05 Jun 2008 16:23:01 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-29</guid>
		<description>Great post! I look forward to more of these.</description>
		<content:encoded><![CDATA[<p>Great post! I look forward to more of these.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NicolÃ¡s Sanguinetti</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-30</link>
		<dc:creator>NicolÃ¡s Sanguinetti</dc:creator>
		<pubDate>Thu, 05 Jun 2008 16:23:01 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-30</guid>
		<description>@David: The parentheses are there to unpack the second item into (k, v) instead of having to split it inside, I didn't know it would give an improvement on performance.

@Andrew: Michel's "quickest version" (the one posted in the first comment) run in 4.98 seconds in my machine, one of the new penryn MacBook Pros (2.4GHz Core 2 Duo, 2GB @667 stock)</description>
		<content:encoded><![CDATA[<p>@David: The parentheses are there to unpack the second item into (k, v) instead of having to split it inside, I didn&#8217;t know it would give an improvement on performance.</p>
<p>@Andrew: Michel&#8217;s &#8220;quickest version&#8221; (the one posted in the first comment) run in 4.98 seconds in my machine, one of the new penryn MacBook Pros (2.4GHz Core 2 Duo, 2GB @667 stock)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Bennett</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-27</link>
		<dc:creator>Andrew Bennett</dc:creator>
		<pubDate>Wed, 04 Jun 2008 16:23:01 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-27</guid>
		<description>Whoops, I hadn't read all of the comments yet when I submitted my post. I thought NicolÃ¡s said that Martin's was 4.98 seconds.

I went ahead tested some of the faster implementations to see who came out winner on my two systems.

The first system is a AMD Athlon XP 2400+ with 2.5GB of RAM running "Linux 2.6.24-17-generic i686" (Ubuntu 8.04)

Andrew:   13.26
Armin #1: 11.45
Armin #2: 15.56
John:      8.81
Luke:     30.18
NicolÃ¡s:  14.09
Martin:   19.71
Michel:   10.33
Ryan:     52.45

The second system is an Intel Xeon 5130 @ 2.00GHz with 2GB of RAM running "FreeBSD 7.0-RELEASE amd64"

Andrew:   4.17
Armin #1: 4.98
Armin #2: 5.43
John:     3.86
Luke:     9.88
NicolÃ¡s:  5.60
Martin:   7.62
Michel:   4.01
Ryan:     21.33

For some reason, Armin's first implementation is faster than mine on 32-bit Linux, while mine is faster than his on 64-bit FreeBSD.

John's implementation still mops the floor with the rest of us.</description>
		<content:encoded><![CDATA[<p>Whoops, I hadn&#8217;t read all of the comments yet when I submitted my post. I thought NicolÃ¡s said that Martin&#8217;s was 4.98 seconds.</p>
<p>I went ahead tested some of the faster implementations to see who came out winner on my two systems.</p>
<p>The first system is a AMD Athlon XP 2400+ with 2.5GB of RAM running &#8220;Linux 2.6.24-17-generic i686&#8243; (Ubuntu 8.04)</p>
<p>Andrew:   13.26<br />
Armin #1: 11.45<br />
Armin #2: 15.56<br />
John:      8.81<br />
Luke:     30.18<br />
NicolÃ¡s:  14.09<br />
Martin:   19.71<br />
Michel:   10.33<br />
Ryan:     52.45</p>
<p>The second system is an Intel Xeon 5130 @ 2.00GHz with 2GB of RAM running &#8220;FreeBSD 7.0-RELEASE amd64&#8243;</p>
<p>Andrew:   4.17<br />
Armin #1: 4.98<br />
Armin #2: 5.43<br />
John:     3.86<br />
Luke:     9.88<br />
NicolÃ¡s:  5.60<br />
Martin:   7.62<br />
Michel:   4.01<br />
Ryan:     21.33</p>
<p>For some reason, Armin&#8217;s first implementation is faster than mine on 32-bit Linux, while mine is faster than his on 64-bit FreeBSD.</p>
<p>John&#8217;s implementation still mops the floor with the rest of us.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-26</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Tue, 03 Jun 2008 16:23:01 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-26</guid>
		<description>Here's one more:

s.split.sort.inject({}) { &#124;h, a&#124; h.merge(a[/^[a-z]/] =&#62; a[/[0-9]+$/].to_i) }

I could be wrong, but I don't think "a20".toi results in 20. I believe, if the number is first, doing a toi on a string will return the number. But when the letter is first, that's not the case, which means that there still needs to be some sort of parsing, rather than a v.to_i implementation, right?

Again, maybe I'm wrong about that.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s one more:</p>
<p>s.split.sort.inject({}) { |h, a| h.merge(a[/^[a-z]/] =&gt; a[/[0-9]+$/].to_i) }</p>
<p>I could be wrong, but I don&#8217;t think &#8220;a20&#8243;.toi results in 20. I believe, if the number is first, doing a toi on a string will return the number. But when the letter is first, that&#8217;s not the case, which means that there still needs to be some sort of parsing, rather than a v.to_i implementation, right?</p>
<p>Again, maybe I&#8217;m wrong about that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Madden</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-24</link>
		<dc:creator>David Madden</dc:creator>
		<pubDate>Tue, 03 Jun 2008 16:14:20 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-24</guid>
		<description>A great post, I love these as its always a good way to pick up tips.

This is especially interesting looking into the dark art of creating hashes using blocks.</description>
		<content:encoded><![CDATA[<p>A great post, I love these as its always a good way to pick up tips.</p>
<p>This is especially interesting looking into the dark art of creating hashes using blocks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-25</link>
		<dc:creator>john</dc:creator>
		<pubDate>Tue, 03 Jun 2008 16:14:20 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-25</guid>
		<description>I suppose these things are system dependeent. I tried the supplied methods and all were clocking in around the 25-30 seconds mark (Yes, I have a slow machine).

Applying a little KISS to the idea I came up with the very simple:

    output  = Hash.new
    inter   = Array.new
    inter   = str.split

    inter.each do &#124;s&#124;
        output[s[0,1]] = s[1,3].to_i
    end

Which clocked in around 12 secs on my machine. It seems that forcing the types might help the compiler instead of making it choose.

Interesting test though.</description>
		<content:encoded><![CDATA[<p>I suppose these things are system dependeent. I tried the supplied methods and all were clocking in around the 25-30 seconds mark (Yes, I have a slow machine).</p>
<p>Applying a little KISS to the idea I came up with the very simple:</p>
<p>    output  = Hash.new<br />
    inter   = Array.new<br />
    inter   = str.split</p>
<p>    inter.each do |s|<br />
        output[s[0,1]] = s[1,3].to_i<br />
    end</p>
<p>Which clocked in around 12 secs on my machine. It seems that forcing the types might help the compiler instead of making it choose.</p>
<p>Interesting test though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Boutros</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-11</link>
		<dc:creator>Michael Boutros</dc:creator>
		<pubDate>Mon, 02 Jun 2008 23:08:08 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-11</guid>
		<description>This is what I'd do, takes less than 0.1 seconds using your benchmark code:

hash = {}; str.split.each {&#124;str&#124; hash.merge!({str[0, 1] =&#62; str[1, 2].to_i})}</description>
		<content:encoded><![CDATA[<p>This is what I&#8217;d do, takes less than 0.1 seconds using your benchmark code:</p>
<p>hash = {}; str.split.each {|str| hash.merge!({str[0, 1] =&gt; str[1, 2].to_i})}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michel</title>
		<link>http://blog.citrusbyte.com/2008/06/02/ruby-tmtowtdi-episode-1/#comment-10</link>
		<dc:creator>Michel</dc:creator>
		<pubDate>Mon, 02 Jun 2008 23:07:27 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/wordpress/?p=24#comment-10</guid>
		<description>The fastest approach I've found so far:

hash = Hash.new; str.scan(/(\w)(\d\d)/).each { &#124;k, v&#124; hash[k] = v.to_i }</description>
		<content:encoded><![CDATA[<p>The fastest approach I&#8217;ve found so far:</p>
<p>hash = Hash.new; str.scan(/(\w)(\d\d)/).each { |k, v| hash[k] = v.to_i }</p>
]]></content:encoded>
	</item>
</channel>
</rss>
