<?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>Samson&#039;s Weblog &#187; Ruby</title>
	<atom:link href="http://blog.samsonis.me/category/technique/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.samsonis.me</link>
	<description>天与弗取，反受其咎；时至不行，反受其殃</description>
	<lastBuildDate>Sun, 29 Jan 2012 13:53:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Downgrade Rubygems</title>
		<link>http://blog.samsonis.me/2011/12/downgrade-rubygems/</link>
		<comments>http://blog.samsonis.me/2011/12/downgrade-rubygems/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 13:09:53 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[RubyGems]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=3661</guid>
		<description><![CDATA[First let&#8217;s list 2 truths here: Rails 2.3.5 will fail with RubyGems 1.5.0 + Rails 2.3.11 will fail with RubyGems 1.7.0 + So what if you want to deploy or run an application which unfortunately still or initially written in rails 2, given the situation that latest RVM default install rubygems version 1.8.11? It turns ...]]></description>
			<content:encoded><![CDATA[<p>First let&#8217;s list 2 truths here:</p>
<ul>
<li>Rails 2.3.5 will fail with RubyGems 1.5.0 +</li>
<li>Rails 2.3.11 will fail with RubyGems 1.7.0 +</li>
</ul>
<p>So what if you want to deploy or run an application which unfortunately still or initially written in rails 2, given the situation that latest RVM default install rubygems version 1.8.11?</p>
<p>It turns out to be not so painful, cause it&#8217;s as simple as just issue one command (take 1.4.2 for example):</p>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem update <span style="color:#006600; font-weight:bold;">--</span><span style="color:#CC0066; font-weight:bold;">system</span> 1.4.2</div></div>
<p>Just like the China highway train, sometimes what you need to do is just to stop moving so fast.</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2011/02/rubygems-1-5-2-manual-upgrade/" title="RubyGems 1.5.2 Manual Upgrade (February 16, 2011)">RubyGems 1.5.2 Manual Upgrade</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/03/archlinux-rvm-ruby-rails-nginx-passenger-and-you/" title="ArchLinux, RVM, Ruby, Rails, Nginx, Passenger and You (March 30, 2011)">ArchLinux, RVM, Ruby, Rails, Nginx, Passenger and You</a> (3)</li>
	<li><a href="http://blog.samsonis.me/2011/03/stdout-deployment/" title="stdout deployment (March 7, 2011)">stdout deployment</a> (4)</li>
	<li><a href="http://blog.samsonis.me/2011/03/stdout-customization/" title="stdout customization (March 7, 2011)">stdout customization</a> (1)</li>
	<li><a href="http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/" title="ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221; (February 21, 2010)">ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221;</a> (2)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2011/12/downgrade-rubygems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ArchLinux, RVM, Ruby, Rails, Nginx, Passenger and You</title>
		<link>http://blog.samsonis.me/2011/03/archlinux-rvm-ruby-rails-nginx-passenger-and-you/</link>
		<comments>http://blog.samsonis.me/2011/03/archlinux-rvm-ruby-rails-nginx-passenger-and-you/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 13:50:08 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[ArchLinux]]></category>
		<category><![CDATA[Passenger]]></category>
		<category><![CDATA[RVM]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=2938</guid>
		<description><![CDATA[没看错，就是ArchLinux，怎么，又回来了？其实我一直未曾离开…… i 好了不矫情了，let&#8217;s do business. [Overview] 本文介绍如何在archlinux上快速搭建rails开发环境，其中有很多可能包括我个人的preferences，各位完全可以根据自行需要取舍。 [ArchLinux] 参照Arch自己的 Official Install Guide ii 安装，其实根本不用参照，整个安装wizard做的已经非常非常user friendly了，我觉得。 [RVM] RVM 的安装依赖 git 和 curl： $ sudo pacman -S git curl 装之： $ bash &#60; &#60;&#40; curl http://rvm.beginrescueend.com/releases/rvm-install-head &#41; 注意没有sudo，符合homebrew的philosophy，尽量不要root，何况我们还是作为development环境，rvm官网好像现在已经没有倾向性了，不过我印象中以前也是倾向于装在user的home目录。 同样是非常友好的安装过程，参照提示，在.bash_profile或者.bashrc的最后添加一行 Load 代码（如果你用的是bash的话）： $ echo '[[ -s &#34;$HOME/.rvm/scripts/rvm&#34; ]] &#38;&#38; . &#34;$HOME/.rvm/scripts/rvm&#34;' &#62;&#62; ~/.bashrc 我还喜欢shell补全，如果你也喜欢，再加上一句即可： $ echo '[[ -r ...]]></description>
			<content:encoded><![CDATA[<p>没看错，就是ArchLinux，怎么，又<a href="http://blog.samsonis.me/tag/archlinux/">回来了</a>？其实我一直未曾离开…… <sup><a href="http://blog.samsonis.me/2011/03/archlinux-rvm-ruby-rails-nginx-passenger-and-you/#footnote_0_2938" id="identifier_0_2938" class="footnote-link footnote-identifier-link" title="我有一个arch的liveusb，各种机子上一直保存着至少2+个arch的vm，虽然后来由于太占空间被转移到了移动硬盘，可就是一直舍不得删">i</a></sup></p>
<p>好了不矫情了，let&#8217;s do business.</p>
<p><span style="text-decoration: underline;">[Overview]</span><br />
本文介绍如何在archlinux上快速搭建rails开发环境，其中有很多可能包括我个人的preferences，各位完全可以根据自行需要取舍。</p>
<p><span style="text-decoration: underline;">[ArchLinux]</span><br />
参照Arch自己的 <a href="https://wiki.archlinux.org/index.php/Official_Arch_Linux_Install_Guide">Official Install Guide</a> <sup><a href="http://blog.samsonis.me/2011/03/archlinux-rvm-ruby-rails-nginx-passenger-and-you/#footnote_1_2938" id="identifier_1_2938" class="footnote-link footnote-identifier-link" title="最近老是official, official的&hellip; 你懂的">ii</a></sup> 安装，其实根本不用参照，整个安装wizard做的已经非常非常user friendly了，我觉得。</p>
<p><span style="text-decoration: underline;">[RVM]</span><br />
<a href="http://rvm.beginrescueend.com/">RVM</a> 的安装依赖 git 和 curl：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> pacman <span style="color: #660033;">-S</span> git curl</div></div>
<p>装之：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> curl http:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>rvm-install-head <span style="color: #7a0874; font-weight: bold;">&#41;</span></div></div>
<p>注意没有sudo，符合homebrew的philosophy，尽量不要root，何况我们还是作为development环境，<a href="http://rvm.beginrescueend.com/rvm/install/">rvm官网</a>好像现在已经没有倾向性了，不过我印象中以前也是倾向于装在user的home目录。<br />
<span id="more-2938"></span><br />
同样是非常友好的安装过程，参照提示，在.bash_profile或者.bashrc的最后添加一行 Load 代码（如果你用的是bash的话）：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'[[ -s &quot;$HOME/.rvm/scripts/rvm&quot; ]] &amp;&amp; . &quot;$HOME/.rvm/scripts/rvm&quot;'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</div></div>
<p>我还喜欢shell补全，如果你也喜欢，再加上一句即可：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'[[ -r $rvm_path/scripts/completion ]] &amp;&amp; . $rvm_path/scripts/completion'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</div></div>
<p>最后查看一下notes，看看所在平台有什么注意事项：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rvm notes</div></div>
<p><span style="text-decoration: underline;">[Ruby]</span><br />
这里我们用rvm安装ruby，如果你喜欢也可以pacman -S之，我查了下，arch repo里的ruby是1.9.2，patch level也是最新的180，不过rvm的好处是可以安装好几个ruby版本，且能够非常方便的帮你维护不同的gemset，非常像python里面的<a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>.</p>
<p>安装最新的ruby 1.9.2:</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.9.2</div></div>
<p>如果需要也可以装上1.8.7的：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.8.7</div></div>
<p>下载编译安装完后我们就可以使用了，我喜欢把ruby 1.9.2，gemset rails3作为我的default：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rvm use 1.9.2<span style="color: #000000; font-weight: bold;">@</span>rails3 <span style="color: #660033;">--create</span> <span style="color: #660033;">--default</span></div></div>
<p>verify一下我们是否还是 so far so good：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">which</span> ruby<br />
<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>samson<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby<br />
$ ruby <span style="color: #660033;">-v</span><br />
ruby 1.9.2p180 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2011</span>-02-<span style="color: #000000;">18</span> revision <span style="color: #000000;">30909</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>x86_64-linux<span style="color: #7a0874; font-weight: bold;">&#93;</span></div></div>
<p><span style="text-decoration: underline;">[Rails]</span><br />
安装rails 3，最新的是3.0.5:</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails</div></div>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">which</span> rails<br />
<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>samson<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>rails3<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rails<br />
$ rails <span style="color: #660033;">-v</span><br />
Rails 3.0.5</div></div>
<p>创建一个project做demo：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rails new demo</div></div>
<p>bundle一下，确保所有依赖的gem都已安装，这里会把sqlite3给补上:</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #7a0874; font-weight: bold;">cd</span> demo<br />
$ bundle</div></div>
<p>又一个milestone，测试一下：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rails s</div></div>
<p><span style="text-decoration: underline;">[Nginx &#038; Passenger]</span><br />
不用apache，让我们换nginx玩玩；由于passenger的nginx模块安装的时候需要重新编译nginx，所以 pacman -S nginx 似乎是没有意义的，我们这里先skip掉，先安装passenger，然后在编译安装passenger的nginx模块的时候把nginx一并搞定。</p>
<p>安装passenger：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> passenger</div></div>
<p>安装passenger的nginx模块，同时安装nginx，默认的nginx安装地址是/opt/nginx（可以修改到不需要root的地址），需要root，我们可以用rvmsudo搞定：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rvmsudo passenger-install-nginx-module</div></div>
<p>again，友好至极，装完连配置文件都帮你改好了，不过检查一下总不会错：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;passenger&quot;</span> nginx.conf<br />
&nbsp; &nbsp; passenger_root <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>samson<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>rails3<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-3.0.5;<br />
&nbsp; &nbsp; passenger_ruby <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>samson<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>wrappers<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>rails3<span style="color: #000000; font-weight: bold;">/</span>ruby;</div></div>
<p>配置一下，来跑一下之前创建的demo project：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">server <span style="color: #7a0874; font-weight: bold;">&#123;</span>¬<br />
&nbsp; listen <span style="color: #000000;">80</span>;¬<br />
&nbsp; server_name demo.local;¬<br />
&nbsp; root <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>samson<span style="color: #000000; font-weight: bold;">/</span>code<span style="color: #000000; font-weight: bold;">/</span>demo<span style="color: #000000; font-weight: bold;">/</span>public;¬<br />
&nbsp; passenger_enabled on;¬<br />
&nbsp; rails_env development;¬<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span>¬</div></div>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>nginx</div></div>
<p>我取的server name时demo.local，所以在hosts里面加上这条entry后，我们就可以用browser访问 http://demo.local 了.</p>
<p>如果遇到403 forbidden，在nginx.conf里面改下user即可：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">user samson <span style="color: #c20cb9; font-weight: bold;">users</span>;</div></div>
<p>reload, welcome aboard!</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #660033;">-s</span> reload</div></div>
[Footnotes]<ol class="footnotes"><li id="footnote_0_2938" class="footnote">我有一个arch的liveusb，各种机子上一直保存着至少2+个arch的vm，虽然后来由于太占空间被转移到了移动硬盘，可就是一直舍不得删</li><li id="footnote_1_2938" class="footnote">最近老是official, official的… 你懂的</li></ol>
	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2009/06/redmine-on-archlinux/" title="Redmine on Archlinux (June 30, 2009)">Redmine on Archlinux</a> (6)</li>
	<li><a href="http://blog.samsonis.me/2009/06/install-ruby-on-rails-on-archlinux/" title="Install Ruby on Rails on Archlinux (June 30, 2009)">Install Ruby on Rails on Archlinux</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2009/05/safeboot%e5%8f%8c%e7%b3%bb%e7%bb%9f%e5%bc%95%e5%af%bc/" title="SafeBoot双系统引导 (May 12, 2009)">SafeBoot双系统引导</a> (29)</li>
	<li><a href="http://blog.samsonis.me/2011/12/downgrade-rubygems/" title="Downgrade Rubygems (December 5, 2011)">Downgrade Rubygems</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2009/02/archlinux%e4%b8%8b%e7%9a%84%e6%97%b6%e9%97%b4%e6%97%b6%e5%8c%ba%e8%ae%be%e7%bd%ae/" title="Archlinux下的时间时区设置 (February 13, 2009)">Archlinux下的时间时区设置</a> (15)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2011/03/archlinux-rvm-ruby-rails-nginx-passenger-and-you/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>stdout customization</title>
		<link>http://blog.samsonis.me/2011/03/stdout-customization/</link>
		<comments>http://blog.samsonis.me/2011/03/stdout-customization/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 10:16:15 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[HostMonster]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=2805</guid>
		<description><![CDATA[前面介绍完了deployment，接下来该轮到customization了，这个也同样重要。我目前所能想到的需要customize的地方主要有5个地方，都集中在两个文件，并没有想象中的复杂，且听我一一道来： [page title] Location: RAILS_ROOT/app/views/layouts/application.html.erb, line 6 &#60;title&#62;$ cat /dev/stdin &#62;&#62; /dev/stdout &#124; tee stdout.samsonw.info&#60;/title&#62; change to whatever text you want. [header title，sub-title] Location: RAILS_ROOT/app/views/activities/index.html.erb, line 2, 3 &#60;div id=&#34;title&#34; class=&#34;grid_24&#34;&#62;$ cat /dev/stdin &#62;&#62; /dev/stdout &#124; tee stdout.samsonw.info&#60;/div&#62; &#60;div id=&#34;sub_title&#34; class=&#34;grid_24&#34;&#62;Don't Panic: fatal system error, core dump file not generated ...&#60;/div&#62; change to whatever text ...]]></description>
			<content:encoded><![CDATA[<p>前面介绍完了<a href="http://blog.samsonis.me/2011/03/stdout-deployment/">deployment</a>，接下来该轮到customization了，这个也同样重要。我目前所能想到的需要customize的地方主要有5个地方，都集中在两个文件，并没有想象中的复杂，且听我一一道来：</p>
<p><span style="text-decoration: underline;">[page title]</span></p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Location: RAILS_ROOT<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts<span style="color: #000000; font-weight: bold;">/</span>application.html.erb, line <span style="color: #000000;">6</span></div></div>
<div class="codecolorer-container ruby railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;</span>title<span style="color:#006600; font-weight:bold;">&gt;</span>$ cat <span style="color:#006600; font-weight:bold;">/</span>dev<span style="color:#006600; font-weight:bold;">/</span>stdin <span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>dev<span style="color:#006600; font-weight:bold;">/</span>stdout <span style="color:#006600; font-weight:bold;">|</span> tee stdout.<span style="color:#9900CC;">samsonw</span>.<span style="color:#9900CC;">info</span><span style="color:#006600; font-weight:bold;">&lt;/</span>title<span style="color:#006600; font-weight:bold;">&gt;</span></div></div>
<p>change to whatever text you want.</p>
<p><span style="text-decoration: underline;">[header title，sub-title]</span></p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Location: RAILS_ROOT<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>activities<span style="color: #000000; font-weight: bold;">/</span>index.html.erb, line <span style="color: #000000;">2</span>, <span style="color: #000000;">3</span></div></div>
<div class="codecolorer-container ruby railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;</span>div id=<span style="color:#996600;">&quot;title&quot;</span> <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;grid_24&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>$ cat <span style="color:#006600; font-weight:bold;">/</span>dev<span style="color:#006600; font-weight:bold;">/</span>stdin <span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>dev<span style="color:#006600; font-weight:bold;">/</span>stdout <span style="color:#006600; font-weight:bold;">|</span> tee stdout.<span style="color:#9900CC;">samsonw</span>.<span style="color:#9900CC;">info</span><span style="color:#006600; font-weight:bold;">&lt;/</span>div<span style="color:#006600; font-weight:bold;">&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;</span>div id=<span style="color:#996600;">&quot;sub_title&quot;</span> <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;grid_24&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>Don<span style="color:#996600;">'t Panic: fatal system error, core dump file not generated ...&lt;/div&gt;</span></div></div>
<p>change to whatever text you want.<br />
<span id="more-2805"></span><br />
<span style="text-decoration: underline;">[footer]</span></p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Location: RAILS_ROOT<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>activities<span style="color: #000000; font-weight: bold;">/</span>index.html.erb, line <span style="color: #000000;">23</span>~<span style="color: #000000;">27</span></div></div>
<div class="codecolorer-container ruby railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;</span>div id=<span style="color:#996600;">&quot;copyright&quot;</span> <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;grid_21&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;</span>p<span style="color:#006600; font-weight:bold;">&gt;</span>卢瑟出品，必属废品<span style="color:#006600; font-weight:bold;">&amp;</span>trade;<span style="color:#006600; font-weight:bold;">&amp;</span>nbsp;<span style="color:#006600; font-weight:bold;">&amp;</span>nbsp;Copyright <span style="color:#006600; font-weight:bold;">&amp;</span>copy; <span style="color:#006666;">2010</span><span style="color:#006600; font-weight:bold;">&amp;</span>ndash;<span style="color:#006666;">2011</span> by <span style="color:#006600; font-weight:bold;">&lt;</span>span <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;losers&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#996600;">&quot;Losers&quot;</span><span style="color:#006600; font-weight:bold;">&lt;/</span>span<span style="color:#006600; font-weight:bold;">&gt;</span> Corporation.<span style="color:#006600; font-weight:bold;">&amp;</span>nbsp;<span style="color:#006600; font-weight:bold;">&amp;</span>nbsp;All Rights Already <span style="color:#006600; font-weight:bold;">&lt;</span>span <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;losers&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>Lost<span style="color:#006600; font-weight:bold;">&lt;/</span>span<span style="color:#006600; font-weight:bold;">&gt;</span>.<span style="color:#006600; font-weight:bold;">&lt;/</span>p<span style="color:#006600; font-weight:bold;">&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;/</span>div<span style="color:#006600; font-weight:bold;">&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;</span>div <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;grid_3&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;</span>div id=<span style="color:#996600;">&quot;curation&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>Curated by <span style="color:#006600; font-weight:bold;">&lt;</span>a id=<span style="color:#996600;">&quot;avatar&quot;</span> href=<span style="color:#996600;">&quot;http://blog.samsonis.me/&quot;</span> target=<span style="color:#996600;">&quot;_blank&quot;</span><span style="color:#006600; font-weight:bold;">&gt;&lt;</span>img src=<span style="color:#996600;">&quot;/images/avatar.jpg&quot;</span> alt=<span style="color:#996600;">&quot;Avatar&quot;</span> title=<span style="color:#996600;">&quot;Samson Wu&quot;</span><span style="color:#006600; font-weight:bold;">&gt;&lt;/</span>a<span style="color:#006600; font-weight:bold;">&gt;&lt;/</span>div<span style="color:#006600; font-weight:bold;">&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;/</span>div<span style="color:#006600; font-weight:bold;">&gt;</span></div></div>
<p>change to whatever text you want.</p>
<p><span style="text-decoration: underline;">[Disqus]</span><br />
到<a href="http://disqus.com/">Disqus</a> register site和profile，然后拿到universal的javascript code，替换我的javascript code，具体位置在：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Location: RAILS_ROOT<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts<span style="color: #000000; font-weight: bold;">/</span>application.html.erb, line <span style="color: #000000;">27</span>~<span style="color: #000000;">42</span></div></div>
<p><span style="text-decoration: underline;">[Google Analytics]</span><br />
同Disqus类似，到<a href="http://www.google.com/analytics/">Google Analytics</a>注册添加site，然后获得javascript code，替换默认的javascript code，位置在：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Location: RAILS_ROOT<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts<span style="color: #000000; font-weight: bold;">/</span>application.html.erb, line <span style="color: #000000;">12</span>~<span style="color: #000000;">22</span></div></div>
<p>Enjoy and have fun!</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2011/03/stdout-deployment/" title="stdout deployment (March 7, 2011)">stdout deployment</a> (4)</li>
	<li><a href="http://blog.samsonis.me/2011/03/stdout-on-github/" title="stdout on github (March 7, 2011)">stdout on github</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2009/06/redmine-on-archlinux/" title="Redmine on Archlinux (June 30, 2009)">Redmine on Archlinux</a> (6)</li>
	<li><a href="http://blog.samsonis.me/2009/06/install-ruby-on-rails-on-archlinux/" title="Install Ruby on Rails on Archlinux (June 30, 2009)">Install Ruby on Rails on Archlinux</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/12/downgrade-rubygems/" title="Downgrade Rubygems (December 5, 2011)">Downgrade Rubygems</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2011/03/stdout-customization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>stdout deployment</title>
		<link>http://blog.samsonis.me/2011/03/stdout-deployment/</link>
		<comments>http://blog.samsonis.me/2011/03/stdout-deployment/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 08:11:33 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[HostMonster]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=2785</guid>
		<description><![CDATA[首先值得一提的是为了支持HostMonster的fastcgi，我人为copy了几个以raild -D生成的项目结构里面的dispatch文件以及create了一个.htaccess文件，如果你不用fastcgi（通常情况下你不需要，而且也不推荐），你可以简单的删除它们（以下RAILS_ROOT是指rails app的根目录）： RAILS_ROOT/config.ru RAILS_ROOT/public/dispatch.cgi RAILS_ROOT/public/dispatch.fcgi RAILS_ROOT/public/dispatch.rb RAILS_ROOT/public/.htaccess [Development Environment] Assume你的os已经装好ruby，如果没有请自行google，这里不再赘述。 首先update一下rubygems，最近rubygems貌似打了鸡血，更新极其频繁… 且bug具多…如果出了问题建议rollback到1.4.2… [Note: 由于我使用rvm，所以以下command都没有sudo，根据你的情况你可能需要加上sudo] $ gem update --system 从github上checkout一份最新的code，rails 2.3.11已经freeze进了source code，所以安装rails并不是必须的： $ git clone git://github.com/samsonw/stdout.git $ cd stdout 复制一份database.yml，不需要什么特别的修改，默认的dev环境配置是使用sqlite3的database： $ cp config/database.yml.example config/database.yml 运行rake db:migrate之前确保已经装好了sqlite3-ruby gem和parse_feeds.rake所依赖的gem，不然rake可能会报错: $ gem install sqlite3-ruby $ gem install base64 json rest-client twitter nokogiri open-uri $ rake db:migrate 如果没有报错，database应该已经建好，接下来我们需要给database populate ...]]></description>
			<content:encoded><![CDATA[<p>首先值得一提的是为了支持HostMonster的fastcgi，我人为copy了几个以raild -D生成的项目结构里面的dispatch文件以及create了一个.htaccess文件，如果你不用fastcgi（通常情况下你不需要，而且也不推荐），你可以简单的删除它们（以下RAILS_ROOT是指rails app的根目录）：</p>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RAILS_ROOT<span style="color:#006600; font-weight:bold;">/</span>config.<span style="color:#9900CC;">ru</span><br />
RAILS_ROOT<span style="color:#006600; font-weight:bold;">/</span>public<span style="color:#006600; font-weight:bold;">/</span>dispatch.<span style="color:#9900CC;">cgi</span><br />
RAILS_ROOT<span style="color:#006600; font-weight:bold;">/</span>public<span style="color:#006600; font-weight:bold;">/</span>dispatch.<span style="color:#9900CC;">fcgi</span><br />
RAILS_ROOT<span style="color:#006600; font-weight:bold;">/</span>public<span style="color:#006600; font-weight:bold;">/</span>dispatch.<span style="color:#9900CC;">rb</span><br />
RAILS_ROOT<span style="color:#006600; font-weight:bold;">/</span>public<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">htaccess</span></div></div>
<p><span style="text-decoration: underline;">[Development Environment]</span><br />
Assume你的os已经装好ruby，如果没有请自行google，这里不再赘述。</p>
<p>首先update一下rubygems，最近rubygems貌似打了鸡血，更新极其频繁… 且bug具多…如果出了问题建议rollback到1.4.2…<br />
[Note: 由于我使用<a href="http://rvm.beginrescueend.com/">rvm</a>，所以以下command都没有sudo，根据你的情况你可能需要加上sudo]</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem update <span style="color: #660033;">--system</span></div></div>
<p><span id="more-2785"></span><br />
从github上checkout一份最新的code，rails 2.3.11已经freeze进了source code，所以安装rails并不是必须的：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ git clone git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>samsonw<span style="color: #000000; font-weight: bold;">/</span>stdout.git<br />
$ <span style="color: #7a0874; font-weight: bold;">cd</span> stdout</div></div>
<p>复制一份database.yml，不需要什么特别的修改，默认的dev环境配置是使用sqlite3的database：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">cp</span> config<span style="color: #000000; font-weight: bold;">/</span>database.yml.example config<span style="color: #000000; font-weight: bold;">/</span>database.yml</div></div>
<p>运行rake db:migrate之前确保已经装好了sqlite3-ruby gem和parse_feeds.rake所依赖的gem，不然rake可能会报错:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> sqlite3-ruby<br />
$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> base64 json rest-client twitter nokogiri open-uri<br />
$ rake db:migrate</div></div>
<p>如果没有报错，database应该已经建好，接下来我们需要给database populate some data，首先来搞Source表，编辑RAILS_ROOT/db/seeds.rb文件，修改blog的link或者删除某些不需要的link，也可以加上你需要的source，我默认加了4个source：</p>
<div class="codecolorer-container ruby railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Source.<span style="color:#9900CC;">find_or_create_by_name</span> <span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;blog&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:display_name</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;Weblog&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:url</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;http://blog.samsonis.me/&quot;</span><br />
Source.<span style="color:#9900CC;">find_or_create_by_name</span> <span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;twitter&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:display_name</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;Twitter&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:url</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;http://twitter.com/&quot;</span><br />
Source.<span style="color:#9900CC;">find_or_create_by_name</span> <span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;sina&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:display_name</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;新浪微博&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:url</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;http://t.sina.com.cn/&quot;</span><br />
Source.<span style="color:#9900CC;">find_or_create_by_name</span> <span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;douban&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:display_name</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;豆瓣&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:url</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;http://www.douban.com/&quot;</span></div></div>
<p>完成后我们就可以populate database：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rake db:seed</div></div>
<p>接下来来搞Activity表，这个表是需要实时更新的（我在production上是半小时一次），数据的更新是通过RAILS_ROOT/lib/tasks/parse_feeds.rake脚本完成的，根据你的需要你需要修改一下这个文件，比如blog的feed地址，sina的username/password，douban的miniblogs feed地址以及twitter的帐号（请自行注意翻墙），根据需要也可以删除或添加新的rake tasks，完成修改后，务必做下测试，我用一个vitual task stdout以简化运行（也为了之后方便cron job配置）：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rake stdout</div></div>
<p>如果需要，你也可以执行单个task：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ rake feeds:parse<br />
$ rake twitter:parse<br />
$ rake sina:parse<br />
$ rake douban:parse</div></div>
<p>如果一切正常，database应该已经populate完成，大功告成，server start，http://localhost:3000/, welcome abroad：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ script<span style="color: #000000; font-weight: bold;">/</span>server</div></div>
<p><span style="text-decoration: underline;">[Production Environment]</span><br />
完成了开发环境的搭建，Production的deployment就会简单很多（当然用fastcgi的不算），因为本质上是差不多的，区别可能只在database和web server的配置之上（我们是卢瑟，没有多少点击率的小site根本不需要load balance，不需要cdn，不需要nosql，不需要distributed）.</p>
<p>database的配置请修改database.yml的production section，比如我们要用mysql database（最新driver是mysql2，不过as you may already know，HostMonser支持只支持mysql，你可以根据你的需要使用mysql2）：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql</div></div>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">production:<br />
&nbsp; adapter: mysql<br />
&nbsp; encoding: utf8<br />
&nbsp; database: MYSQL_DATABASE_NAME<br />
&nbsp; pool: <span style="color:#006666;">5</span><br />
&nbsp; username: MYSQL_USER<br />
&nbsp; password: PASSWORD<br />
&nbsp; host: localhost</div></div>
<p>web/app server建议使用passenger，然后apache抑或nginx，这里不再赘述；当然你也可以直接mongrel或是webrick抑或fastcgi.</p>
<p>最后你还需要配置一个cron job，定时更新数据，我在Production上每30分钟更新一次，你可以根据你的需要配置，比如某些话捞可能需要15分钟一次甚至5分钟一次：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">15</span>,<span style="color: #000000;">45</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> &nbsp;<span style="color: #7a0874; font-weight: bold;">cd</span> RAILS_ROOT <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> rake <span style="color: #007800;">RAILS_ENV</span>=<span style="color: #ff0000;">&quot;production&quot;</span> stdout <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></div></div>
<p>能回忆记起的大致就这些了，如果deploy中有问题请留言，I&#8217;m more than happy to assist.</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2011/03/stdout-customization/" title="stdout customization (March 7, 2011)">stdout customization</a> (1)</li>
	<li><a href="http://blog.samsonis.me/2011/03/stdout-on-github/" title="stdout on github (March 7, 2011)">stdout on github</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2009/06/redmine-on-archlinux/" title="Redmine on Archlinux (June 30, 2009)">Redmine on Archlinux</a> (6)</li>
	<li><a href="http://blog.samsonis.me/2009/06/install-ruby-on-rails-on-archlinux/" title="Install Ruby on Rails on Archlinux (June 30, 2009)">Install Ruby on Rails on Archlinux</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/12/downgrade-rubygems/" title="Downgrade Rubygems (December 5, 2011)">Downgrade Rubygems</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2011/03/stdout-deployment/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>stdout on github</title>
		<link>http://blog.samsonis.me/2011/03/stdout-on-github/</link>
		<comments>http://blog.samsonis.me/2011/03/stdout-on-github/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 05:23:57 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[Loser]]></category>
		<category><![CDATA[LoserLogs]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=2778</guid>
		<description><![CDATA[stdout, aka LoserLogs or LoserStream is finally on github, check out at https://github.com/samsonw/stdout . The code is based on rails 2.3.11 instead of rails 3, quite a surprise, isn&#8217;t it? Actually I was planning to, but after some research, it turns out my shared host provider HostMonster only support rails 2 at the time of ...]]></description>
			<content:encoded><![CDATA[<p>stdout, aka LoserLogs or <a href="http://blog.samsonis.me/2011/03/stdout-samsonw-info/#comment-1612">LoserStream</a> is finally on github, check out at <a href="https://github.com/samsonw/stdout">https://github.com/samsonw/stdout</a> .</p>
<p>The code is based on rails 2.3.11 instead of rails 3, quite a surprise, isn&#8217;t it?  Actually I was planning to, but after some research, it turns out my shared host provider <a href="http://www.hostmonster.com/">HostMonster</a> only support rails 2 at the time of this writing, shame on them.</p>
<p>It was always quite enjoyable to figure this and that out in the process of curating that site, except the deployment experiences on HostMonster.  To my surprise, they&#8217;re still using Fastcgi to support rails application, again, shame on them.</p>
<p>Last but not least, the project is called &#8220;LoserLogs&#8221; and copyrighted by &#8220;Losers&#8221; corporation, cause I and along with some of my friends are all having the &#8220;loser&#8221; faith in our heart, this is NOT a joke :)</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2011/03/stdout-samsonw-info/" title="stdout.samsonw.info (March 4, 2011)">stdout.samsonw.info</a> (3)</li>
	<li><a href="http://blog.samsonis.me/2011/03/stdout-deployment/" title="stdout deployment (March 7, 2011)">stdout deployment</a> (4)</li>
	<li><a href="http://blog.samsonis.me/2011/03/stdout-customization/" title="stdout customization (March 7, 2011)">stdout customization</a> (1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2011/03/stdout-on-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RubyGems 1.5.2 Manual Upgrade</title>
		<link>http://blog.samsonis.me/2011/02/rubygems-1-5-2-manual-upgrade/</link>
		<comments>http://blog.samsonis.me/2011/02/rubygems-1-5-2-manual-upgrade/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 07:02:04 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[RubyGems]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=2732</guid>
		<description><![CDATA[今天想更新RubyGems，突然发现 gem update &#8211;&#8211;system 貌似不work了： $ gem -v 1.5.0 $ gem update --system Updating RubyGems ERROR: &#160;While executing gem ... &#40;NoMethodError&#41; &#160; &#160; undefined method `version' for nil:NilClass turns out 这是 RubyGems 1.5.0 和 1.5.1 的一个bug，1.5.2 fix了这个issue。 Manual的Upgrade可以绕过 reinstall 的麻烦和繁琐，且更低碳环保： $ gem install rubygems-update Fetching: rubygems-update-1.5.2.gem &#40;100%&#41; Successfully installed rubygems-update-1.5.2 1 gem installed $ update_rubygems ...]]></description>
			<content:encoded><![CDATA[<p>今天想更新RubyGems，突然发现 gem update &ndash;&ndash;system 貌似不work了：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem <span style="color: #660033;">-v</span><br />
1.5.0</div></div>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem update <span style="color: #660033;">--system</span><br />
Updating RubyGems<br />
ERROR: &nbsp;While executing gem ... <span style="color: #7a0874; font-weight: bold;">&#40;</span>NoMethodError<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; undefined method <span style="color: #000000; font-weight: bold;">`</span>version<span style="color: #ff0000;">' for nil:NilClass</span></div></div>
<p>turns out 这是 <a href="https://github.com/rubygems/rubygems/commit/9defc03d8d8b8c0703566aa851523006c41c3a70">RubyGems 1.5.0 和 1.5.1 的一个bug</a>，1.5.2 fix了这个issue。</p>
<p>Manual的Upgrade可以绕过 reinstall 的麻烦和繁琐，且更低碳环保：<br />
<span id="more-2732"></span></p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> rubygems-update<br />
Fetching: rubygems-update-1.5.2.gem <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
Successfully installed rubygems-update-1.5.2<br />
<span style="color: #000000;">1</span> gem installed</div></div>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ update_rubygems <br />
RubyGems 1.5.2 installed<br />
<br />
=== 1.5.2 <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">2011</span>-02-<span style="color: #000000;">10</span><br />
<br />
NOTE: &nbsp;RubyGems 1.5.0 and 1.5.1 have a broken <span style="color: #000000; font-weight: bold;">&lt;</span>tt<span style="color: #000000; font-weight: bold;">&gt;</span>gem update --system<span style="color: #000000; font-weight: bold;">&lt;/</span>tt<span style="color: #000000; font-weight: bold;">&gt;</span>.<br />
<br />
To upgrade you<span style="color: #ff0000;">'ll need to use the manual upgrade recipe. &nbsp;Using sudo/su as<br />
appropriate:<br />
<br />
&nbsp; $ gem install rubygems-update<br />
&nbsp; $ update_rubygems<br />
<br />
Bug Fixes:<br />
<br />
* Fixed &lt;tt&gt;gem update --system&lt;/tt&gt;. &nbsp;RubyGems can now update itself again.<br />
<br />
<br />
---------------------------------------------------------------------------<br />
<br />
RubyGems installed the following executables:<br />
&nbsp; &nbsp; /Users/samson/.rvm/rubies/ruby-1.9.2-p136/bin/gem</span></div></div>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2011/12/downgrade-rubygems/" title="Downgrade Rubygems (December 5, 2011)">Downgrade Rubygems</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/" title="ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221; (February 21, 2010)">ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221;</a> (2)</li>
	<li><a href="http://blog.samsonis.me/2010/02/ruby-gem-geoip-and-rack-geoipcountry/" title="Ruby gem geoip and Rack::GeoIPCountry (February 25, 2010)">Ruby gem geoip and Rack::GeoIPCountry</a> (2)</li>
	<li><a href="http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/" title="List performance: ruby 1.8 and 1.9 (Part 1) (February 22, 2010)">List performance: ruby 1.8 and 1.9 (Part 1)</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/03/archlinux-rvm-ruby-rails-nginx-passenger-and-you/" title="ArchLinux, RVM, Ruby, Rails, Nginx, Passenger and You (March 30, 2011)">ArchLinux, RVM, Ruby, Rails, Nginx, Passenger and You</a> (3)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2011/02/rubygems-1-5-2-manual-upgrade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gem list</title>
		<link>http://blog.samsonis.me/2010/09/gem-list/</link>
		<comments>http://blog.samsonis.me/2010/09/gem-list/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 15:50:37 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[Share]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=2201</guid>
		<description><![CDATA[响应蛋疼之号召，gem list一下，不过估计有点outdated，因为本人最近好几个月没碰ruby了，不过anyway，show了再说： $ gem list --local &#124; wc -l 147 为了有点视觉效果，特地把vertical scrollbar给干掉了，xd： $ gem list --local *** LOCAL GEMS *** actionmailer &#40;2.3.5, 2.3.4, 2.3.3, 2.3.2&#41; actionpack &#40;2.3.5, 2.3.4, 2.3.3, 2.3.2&#41; activemerchant &#40;1.5.1&#41; activerecord &#40;2.3.5, 2.3.4, 2.3.3, 2.3.2&#41; activerecord-tableless &#40;0.1.0&#41; activeresource &#40;2.3.5, 2.3.4, 2.3.3, 2.3.2&#41; activesupport &#40;2.3.5, 2.3.4, 2.3.3, 2.3.2&#41; authlogic &#40;2.1.3&#41; authlogic-oid &#40;1.0.4&#41; autotest &#40;4.2.9&#41; ...]]></description>
			<content:encoded><![CDATA[<p>响应<a href="http://sunng.info/blog/2010/09/ls-my-python-packages/">蛋疼之号召</a>，gem list一下，不过估计有点outdated，因为本人最近好几个月没碰ruby了，不过anyway，show了再说：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem list <span style="color: #660033;">--local</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span><br />
<span style="color: #000000;">147</span></div></div>
<p>为了有点视觉效果，特地把vertical scrollbar给干掉了，xd：<br />
<span id="more-2201"></span></p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem list <span style="color: #660033;">--local</span><br />
<br />
<span style="color: #000000; font-weight: bold;">***</span> LOCAL GEMS <span style="color: #000000; font-weight: bold;">***</span><br />
<br />
actionmailer <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.5, 2.3.4, 2.3.3, 2.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
actionpack <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.5, 2.3.4, 2.3.3, 2.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
activemerchant <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.5.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
activerecord <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.5, 2.3.4, 2.3.3, 2.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
activerecord-tableless <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.1.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
activeresource <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.5, 2.3.4, 2.3.3, 2.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
activesupport <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.5, 2.3.4, 2.3.3, 2.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
authlogic <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.1.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
authlogic-oid <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
autotest <span style="color: #7a0874; font-weight: bold;">&#40;</span>4.2.9<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
autotest-fsevent <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.2, 0.1.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
autotest-growl <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.3, 0.1.6<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
autotest-rails <span style="color: #7a0874; font-weight: bold;">&#40;</span>4.1.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
autotest-rails-pure <span style="color: #7a0874; font-weight: bold;">&#40;</span>4.1.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
awesome_print <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.1.4, 0.1.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
billing <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.1.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
builder <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.1.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
bundler <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.9.17, 0.9.16, 0.9.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
cache-money <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
calendar_date_select <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.16.1, <span style="color: #000000;">1.15</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
cgi_multipart_eof_fix <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.5.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
cheat <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
chronic <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
collectiveidea-awesome_nested_set <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
columnize <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
commondream-control_center <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
configuration <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.0, 0.0.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
crack <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.1.7, 0.1.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
cucumber <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.6.4, 0.6.2, 0.3.104<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
curb <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.7.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
daemons <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.10<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
dependencies <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0.9, 0.0.6<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
diff-lcs <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
echoe <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4.3</span>, <span style="color: #000000;">3.2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
eventmachine <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.12.10, 0.12.8<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
faker <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
fastthread <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.7<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
flay <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
flog <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.4.0, 2.2.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
gem_plugin <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
gemcutter <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.5.0, 0.4.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
geoip <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.6<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
ghost <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.7, 0.2.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
git <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
gruff <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.6<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
haml <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.2.22, 2.2.20, 2.2.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
happymapper <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
highline <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.5.2, 1.5.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
hirb <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.1, 0.2.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
hoe <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.6.0, 2.3.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
hpricot <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.2, 0.8.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
httpclient <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.1.5.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
javan-whenever <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.7<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
jeweler <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
jnunemaker-validatable <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.8.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
jscruggs-metric_fu <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
json <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.3, 1.2.0, 1.1.9<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
json_pure <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.3, 1.2.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
laserlemon-vestal_versions <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.0, 0.6.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
launchy <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.5, 0.3.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #c20cb9; font-weight: bold;">less</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.21, 1.2.20<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
libxml-ruby <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
linecache <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.43</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
little-plugger <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.2, 1.1.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
log4r <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.7, 1.1.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
logging <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.1, 1.3.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
looksee <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
magic_multi_connections <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
memcache-client <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.8.2, 1.8.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
memcached <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.19.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mime-types <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1.16</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mislav-will_paginate <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.11<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mocha <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.9.8, 0.9.7<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mojombo-chronic <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mongo <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.20</span>, 0.19.3, 0.19.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mongo_ext <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.19.3, 0.19.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mongo_mapper <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.7.3, 0.7.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mongrel <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mozy_api <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.1.42<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mutter <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.5.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
mysql <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.8.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
nokogiri <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.1, 1.3.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
paperclip <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.1.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
passenger <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.2.11<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
polyglot <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.1, 0.3.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
postgres <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.7.9.2008.01.28<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
production_log_analyzer <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.5.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rack <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.0, 1.0.1, 1.0.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rack-bug <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rack-test <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.5.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
radiant <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rails <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.5, 2.3.4, 2.3.3, 2.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rails-footnotes <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.6.6<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rails_analyzer_tools <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rake <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.7<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rava <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rb-appscript <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.5.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rcov <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.9.8, 0.8.1.2.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
RedCloth <span style="color: #7a0874; font-weight: bold;">&#40;</span>4.2.3, 4.2.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
redgreen <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
reek <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.7.3, 1.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
relevance-rcov <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.9.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
request-log-analyzer <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.6.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rest-client <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.2, 1.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rmagick <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.13.1, 2.12.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
roodi <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.1.0, 2.0.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rr <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.10.11, 0.10.10<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rspec <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.3.0, 1.2.8<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rspec-rails <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.3.2, 1.2.7.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
ruby-debug <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.10.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
ruby-debug-base <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.10.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
ruby-debug-ide <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.4.9, 0.4.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
ruby-hmac <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.4.0, 0.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
ruby2ruby <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
ruby_parser <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.0.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rubyforge <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.0.4, 1.0.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
rubygems-update <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.3.7, 1.3.6, 1.3.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
savon <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.7.6, 0.6.7<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
searchlogic <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.4.14, 2.3.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
sexp_processor <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.4, 3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
shotgun <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.6</span>, <span style="color: #000000;">0.4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
sinatra <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1.0</span>, 0.9.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
sketches <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.1.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
soap4r <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.5.8<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
spree <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.10.2, 0.8.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
sqlite3-ruby <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
state_machine <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.1, 0.8.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
stringex <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.0, 1.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
sys-uname <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.4, 0.8.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
SyslogLogger <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
system_timer <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1.0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
term-ansicolor <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.5, 1.0.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
thin <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.7, 1.2.5, 1.2.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
thor <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.13.4, 0.11.5<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
thoughtbot-shoulda <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.10.2<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
tlsmail <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
treetop <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.5, 1.4.4<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
unicode <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
validatable <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.6.7<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
visionmedia-terminal-table <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.0<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
webrat <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.7.0, 0.5.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
whenever <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.4.1, 0.3.7<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
will_paginate <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.12, 2.3.11<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
wirble <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.1.3<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
xml-simple <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.12<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
ZenTest <span style="color: #7a0874; font-weight: bold;">&#40;</span>4.3.1, 4.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
zentest-without-autotest <span style="color: #7a0874; font-weight: bold;">&#40;</span>4.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span></div></div>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2010/08/%e8%af%b4%e8%b0%8e/" title="说谎 (August 9, 2010)">说谎</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/01/%e8%8a%82%e9%80%89%e4%b8%a4%e6%ae%b5%e5%a5%a5%e5%b7%b4%e9%a9%ac2011%e5%9b%bd%e6%83%85%e5%92%a8%e6%96%87/" title="节选两段奥巴马2011国情咨文 (January 26, 2011)">节选两段奥巴马2011国情咨文</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2010/07/%e7%8b%ae%e5%ad%90%e5%ba%a7/" title="狮子座 (July 31, 2010)">狮子座</a> (16)</li>
	<li><a href="http://blog.samsonis.me/2010/02/%e6%9c%aa%e6%88%90%e5%b9%b4%e5%85%88%e5%88%ab%e5%84%aa/" title="未成年先别優 (February 23, 2010)">未成年先别優</a> (1)</li>
	<li><a href="http://blog.samsonis.me/2011/01/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aareader-app%e5%92%8c%e4%b8%80%e4%b8%aagreasemonkey%e8%84%9a%e6%9c%ac/" title="推荐一个reader app和一个Greasemonkey脚本 (January 26, 2011)">推荐一个reader app和一个Greasemonkey脚本</a> (2)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2010/09/gem-list/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ruby gem geoip and Rack::GeoIPCountry</title>
		<link>http://blog.samsonis.me/2010/02/ruby-gem-geoip-and-rack-geoipcountry/</link>
		<comments>http://blog.samsonis.me/2010/02/ruby-gem-geoip-and-rack-geoipcountry/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 08:51:44 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[geo]]></category>
		<category><![CDATA[Rack]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=1733</guid>
		<description><![CDATA[wikipedia上对于geolocation的解释是这样的： Geolocation is the identification of the real-world geographic location of an Internet-connected computer, mobile device, website visitor or other. 检测的方法貌似也有很多： Geolocation can be performed by associating a geographic location with the Internet Protocol (IP) address, MAC address, RFID, hardware embedded article/production number, embedded software number (such as UUID, Exif/IPTC/XMP or modern steganography), invoice, Wi-Fi ...]]></description>
			<content:encoded><![CDATA[<p>wikipedia上对于<a href="http://en.wikipedia.org/wiki/Geolocation">geolocation</a>的解释是这样的：</p>
<blockquote><p>
Geolocation is the identification of the real-world geographic location of an Internet-connected computer, mobile device, website visitor or other.
</p></blockquote>
<p>检测的方法貌似也有很多：</p>
<blockquote><p>Geolocation can be performed by associating a geographic location with the Internet Protocol (IP) address, MAC address, RFID, hardware embedded article/production number, embedded software number (such as UUID, Exif/IPTC/XMP or modern steganography), invoice, Wi-Fi  connection location, or device GPS  coordinates, or other, perhaps self-disclosed information.</p></blockquote>
<p>（班门弄斧一下先，呵呵呵呵）</p>
<p>ruby里面取到geo信息的一个相对方便的办法是使用rubygem <a href="http://geoip.rubyforge.org/">geoip</a>，虽然本质上还是使用<a href="http://www.maxmind.com/">maxmind</a>的data，但是免去了编译和安装其c library的麻烦。<br />
<span id="more-1733"></span><br />
安装gem并下载其depend到的geoip database：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> geoip</div></div>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>geolite.maxmind.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>geoip<span style="color: #000000; font-weight: bold;">/</span>database<span style="color: #000000; font-weight: bold;">/</span>GeoLiteCountry<span style="color: #000000; font-weight: bold;">/</span>GeoIP.dat.gz <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">gunzip</span> GeoIP.dat.gz</div></div>
<p>如果想要城市信息，还可以下载稍微大一点的带city info的free database：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>geolite.maxmind.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>geoip<span style="color: #000000; font-weight: bold;">/</span>database<span style="color: #000000; font-weight: bold;">/</span>GeoLiteCity.dat.gz <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">gunzip</span> GeoLiteCity.dat.gz</div></div>
<p>简单的测试一下：</p>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'geoip'</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">p</span> GeoIP.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'GeoIP.dat'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">country</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;google.com&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> GeoIP.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'GeoLiteCity.dat'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">city</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;baidu.com&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></div>
<p>alright, looks good:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;google.com&quot;</span>, <span style="color: #ff0000;">&quot;66.249.91.104&quot;</span>, <span style="color: #000000;">225</span>, <span style="color: #ff0000;">&quot;US&quot;</span>, <span style="color: #ff0000;">&quot;USA&quot;</span>, <span style="color: #ff0000;">&quot;United States&quot;</span>, <span style="color: #ff0000;">&quot;NA&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;baidu.com&quot;</span>, <span style="color: #ff0000;">&quot;220.181.6.81&quot;</span>, <span style="color: #ff0000;">&quot;CN&quot;</span>, <span style="color: #ff0000;">&quot;CHN&quot;</span>, <span style="color: #ff0000;">&quot;China&quot;</span>, <span style="color: #ff0000;">&quot;AS&quot;</span>, <span style="color: #ff0000;">&quot;22&quot;</span>, <span style="color: #ff0000;">&quot;Beijing&quot;</span>, <span style="color: #ff0000;">&quot;&quot;</span>, <span style="color: #000000;">39.9289</span>, <span style="color: #000000;">116.3883</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></div></div>
<p>由于geo的普遍性，把其做成可以plug&#038;play的Rack middleware绝对是个好主意，这就是接下来要介绍的<a href="http://coderack.org/users/hosiawak/entries/36-geoip-country">Rack::GeoIPCountry</a>，<a href="http://coderack.org/">CodeRack Contest</a>的first place。</p>
<p>其原理就是调用geoip gem获得访问IP的geo信息并写入request header，这样后面的app或者middleware就能读到并处理了。</p>
<p>同样写个简单的middleware测试一下：</p>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'geo_ip_country'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> GeoTest<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>app<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@app</span> = app<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> call<span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Remote Address: #{env['REMOTE_ADDR']}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;GeoIP Country ID: #{env['X_GEOIP_COUNTRY_ID']}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;GeoIP Country Code: #{env['X_GEOIP_COUNTRY_CODE']}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;GeoIP Country Code3: #{env['X_GEOIP_COUNTRY_CODE3']}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;GeoIP Country: #{env['X_GEOIP_COUNTRY']}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;GeoIP Continent: #{env['X_GEOIP_CONTINENT']}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@app</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
use <span style="color:#6666ff; font-weight:bold;">Rack::ContentLength</span><br />
use <span style="color:#6666ff; font-weight:bold;">Rack::GeoIPCountry</span><br />
use GeoTest<br />
<br />
run <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>env<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">200</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">'Content-Type'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'text/html'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#996600;">'OK'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div></div>
<p>rackup起来后，访问http://localhost:9292，确认console下输出了我们想要的geo信息：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Remote Address: 127.0.0.1<br />
GeoIP Country ID: <span style="color: #000000;">0</span><br />
GeoIP Country Code: <span style="color: #660033;">--</span><br />
GeoIP Country Code3: <span style="color: #660033;">--</span><br />
GeoIP Country: N<span style="color: #000000; font-weight: bold;">/</span>A<br />
GeoIP Continent: <span style="color: #660033;">--</span><br />
127.0.0.1 - - <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">25</span><span style="color: #000000; font-weight: bold;">/</span>Feb<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2010</span> <span style="color: #000000;">16</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">11</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #ff0000;">&quot;GET / HTTP/1.1&quot;</span> <span style="color: #000000;">200</span> <span style="color: #000000;">2</span> <span style="color: #000000;">0.0016</span></div></div>
<p>当然上面的127.0.0.1是不会有任何信息的，local network也是不会在database里面找到对应的，只有当真正的外网ip hit到我们的server时，我们才能看到有意义的geo信息。</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/" title="ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221; (February 21, 2010)">ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221;</a> (2)</li>
	<li><a href="http://blog.samsonis.me/2011/02/rubygems-1-5-2-manual-upgrade/" title="RubyGems 1.5.2 Manual Upgrade (February 16, 2011)">RubyGems 1.5.2 Manual Upgrade</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/" title="List performance: ruby 1.8 and 1.9 (Part 1) (February 22, 2010)">List performance: ruby 1.8 and 1.9 (Part 1)</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/12/downgrade-rubygems/" title="Downgrade Rubygems (December 5, 2011)">Downgrade Rubygems</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/03/archlinux-rvm-ruby-rails-nginx-passenger-and-you/" title="ArchLinux, RVM, Ruby, Rails, Nginx, Passenger and You (March 30, 2011)">ArchLinux, RVM, Ruby, Rails, Nginx, Passenger and You</a> (3)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2010/02/ruby-gem-geoip-and-rack-geoipcountry/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>List performance: ruby 1.8 and 1.9 (Part 2)</title>
		<link>http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-2/</link>
		<comments>http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-2/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 05:54:36 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=1654</guid>
		<description><![CDATA[接上篇： List performance: ruby 1.8 and 1.9 (Part 1) 有了之前的准备和热身，真正跑起步来似乎轻松不少，先贴上我们用来benchmark的code： require 'benchmark' n = ARGV.empty? ? 10 ** 6 : 10 ** ARGV&#91;0&#93;.to_i puts &#34;n=#{n}&#34; Benchmark.bmbm do &#124;x&#124; &#160; x.report do &#160; &#160; list = &#91;&#93; &#160; &#160; n.times do &#160; &#160; &#160; list &#60;&#60; 0 &#160; &#160; end &#160; end end 和之前用来benchmark loop performance的code结构上基本没有区别，这里不再赘述，具体的解释亦可参照前文。 ...]]></description>
			<content:encoded><![CDATA[<p>接上篇： <a href="http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/">List performance: ruby 1.8 and 1.9 (Part 1)</a></p>
<p>有了之前的准备和热身，真正跑起步来似乎轻松不少，先贴上我们用来benchmark的code：</p>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'benchmark'</span><br />
<br />
n = ARGV.<span style="color:#9900CC;">empty</span>? ? <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">**</span> <span style="color:#006666;">6</span> : <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">**</span> ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;n=#{n}&quot;</span><br />
<span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bmbm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; x.<span style="color:#9900CC;">report</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; list = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; n.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; list <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006666;">0</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>和<a href="http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/#more-1621">之前</a>用来benchmark loop performance的code结构上基本没有区别，这里不再赘述，具体的解释亦可参照前文。<br />
<span id="more-1654"></span><br />
下面分别是ruby 1.8和ruby 1.9的一次完整运行（ n=10~10^8 ）的数据结果（也是我唯一运行的一次…）</p>
<p>ruby 1.8:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">n</span>=<span style="color: #000000;">10</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000014</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000012</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000118</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000061</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">1000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000375</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000314</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">10000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.002900</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.002790</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.027712</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.030000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.020000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.020000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.027713</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">1000000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.280000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.290000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.323298</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.290000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.280000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.290000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.283621</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">10000000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">2.740000</span> &nbsp; <span style="color: #000000;">0.050000</span> &nbsp; <span style="color: #000000;">2.790000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">2.809917</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 2.790000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">2.760000</span> &nbsp; <span style="color: #000000;">0.040000</span> &nbsp; <span style="color: #000000;">2.800000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">2.810491</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100000000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; <span style="color: #000000;">27.410000</span> &nbsp; <span style="color: #000000;">0.490000</span> &nbsp;<span style="color: #000000;">27.900000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">28.164103</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">--------------------------</span> total: 27.900000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; <span style="color: #000000;">27.620000</span> &nbsp; <span style="color: #000000;">0.480000</span> &nbsp;<span style="color: #000000;">28.100000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">28.230073</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================</div></div>
<p>ruby 1.9:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">n</span>=<span style="color: #000000;">10</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000068</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000012</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000038</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000032</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">1000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000297</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000209</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">10000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.002164</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.002025</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.020000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.020000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.020366</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.020000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.020000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.020000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.020873</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">1000000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">0.190000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.200000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.208302</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 0.200000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">0.190000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.190000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.208822</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">10000000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; &nbsp;<span style="color: #000000;">1.920000</span> &nbsp; <span style="color: #000000;">0.050000</span> &nbsp; <span style="color: #000000;">1.970000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">2.050276</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------</span> total: 1.970000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; &nbsp;<span style="color: #000000;">1.920000</span> &nbsp; <span style="color: #000000;">0.050000</span> &nbsp; <span style="color: #000000;">1.970000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">2.054335</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100000000</span><br />
Rehearsal <span style="color: #660033;">------------------------------------</span><br />
&nbsp; <span style="color: #000000;">19.220000</span> &nbsp; <span style="color: #000000;">0.460000</span> &nbsp;<span style="color: #000000;">19.680000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">20.466960</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">--------------------------</span> total: 19.680000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
&nbsp; <span style="color: #000000;">19.220000</span> &nbsp; <span style="color: #000000;">0.460000</span> &nbsp;<span style="color: #000000;">19.680000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">20.546417</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
==============================================</div></div>
<p>就这次运行的结果而言，ruby 1.9的performance平均都有25%～35%的提升，加之<a href="http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/">Part 1</a>测试过的循环性能的倒退，则更可以确定list append操作的performance确实在1.9里面较1.8有了很大的提高。</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/" title="List performance: ruby 1.8 and 1.9 (Part 1) (February 22, 2010)">List performance: ruby 1.8 and 1.9 (Part 1)</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/02/rubygems-1-5-2-manual-upgrade/" title="RubyGems 1.5.2 Manual Upgrade (February 16, 2011)">RubyGems 1.5.2 Manual Upgrade</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/" title="ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221; (February 21, 2010)">ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221;</a> (2)</li>
	<li><a href="http://blog.samsonis.me/2010/02/ruby-gem-geoip-and-rack-geoipcountry/" title="Ruby gem geoip and Rack::GeoIPCountry (February 25, 2010)">Ruby gem geoip and Rack::GeoIPCountry</a> (2)</li>
	<li><a href="http://blog.samsonis.me/2011/12/downgrade-rubygems/" title="Downgrade Rubygems (December 5, 2011)">Downgrade Rubygems</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-2/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>List performance: ruby 1.8 and 1.9 (Part 1)</title>
		<link>http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/</link>
		<comments>http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 02:47:02 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=1621</guid>
		<description><![CDATA[（本文数据较多，在rss reader里面可能可读性不是很好，可考虑直接在线阅读） 昨天看到pipitu的这篇blog，觉得蛮有意思，文章比较了python和java的list performance，只可惜没有include ruby 1.8和ruby 1.9，不然结论会更有悬念一点，呵呵. 由于无法营造一致的软硬件环境，也不愿意重复pipitu关于python和java部分的工作，这里就只好先简单benchmark（如果可以算是的话）一下ruby 1.8和1.9里的list (array) performance了，也许pipitu以后有空更新include ruby也说不定：） 先看一下我们用的ruby的版本： $ ruby -v ruby 1.8.7 &#40;2009-06-12 patchlevel 174&#41; &#91;i686-darwin9&#93; $ ruby1.9 -v ruby 1.9.1p376 &#40;2009-12-07 revision 26041&#41; &#91;i386-darwin9&#93; 还有os： $ uname -a Darwin macbook.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386 benchmark的方法和pipitu的python sample类似，就是往空的list里面循环n次append，由于循环也被引入，其performance也值得考虑，因为众所周知ruby里面做一件事犹如孔乙己的茴字写法一样有n种办法，其performance也各不一样，说不定pipitu以后会和python, java进行横向，咱还是挑相对快一点的好～ 不过话说回来，再怎么的精挑细选，java那边还是基本没有悬念，真正有悬念的，我们都心知肚明，呵呵。 所以真正运动之前先来点热身运动，看看哪个循环在我这相对要快： ...]]></description>
			<content:encoded><![CDATA[<p>（本文数据较多，在rss reader里面可能可读性不是很好，可考虑直接<a href="http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/">在线</a>阅读）</p>
<p>昨天看到<a href="http://pipitu.org/">pipitu</a>的<a href="http://pipitu.org/2010/02/20/list-performance-python-vs-java/">这篇blog</a>，觉得蛮有意思，文章比较了python和java的list performance，只可惜没有include ruby 1.8和ruby 1.9，不然结论会更有悬念一点，呵呵.</p>
<p>由于无法营造一致的软硬件环境，也不愿意重复pipitu关于python和java部分的工作，这里就只好先简单benchmark（如果可以算是的话）一下ruby 1.8和1.9里的list (array) performance了，也许pipitu以后有空更新include ruby也说不定：）</p>
<p>先看一下我们用的ruby的版本：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ruby <span style="color: #660033;">-v</span><br />
ruby 1.8.7 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2009</span>-06-<span style="color: #000000;">12</span> patchlevel <span style="color: #000000;">174</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i686-darwin9<span style="color: #7a0874; font-weight: bold;">&#93;</span></div></div>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ruby1.9 <span style="color: #660033;">-v</span><br />
ruby 1.9.1p376 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2009</span>-<span style="color: #000000;">12</span>-07 revision <span style="color: #000000;">26041</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i386-darwin9<span style="color: #7a0874; font-weight: bold;">&#93;</span></div></div>
<p>还有os：</p>
<div class="codecolorer-container bash railscasts" style="border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">uname</span> <span style="color: #660033;">-a</span><br />
Darwin macbook.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul <span style="color: #000000;">15</span> <span style="color: #000000;">16</span>:<span style="color: #000000;">55</span>:01 PDT <span style="color: #000000;">2009</span>; root:xnu-1228.15.4~<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>RELEASE_I386 i386</div></div>
<p><span id="more-1621"></span><br />
benchmark的方法和pipitu的python sample类似，就是往空的list里面循环n次append，由于循环也被引入，其performance也值得考虑，因为众所周知ruby里面做一件事犹如孔乙己的茴字写法一样有n种办法，其performance也各不一样，说不定pipitu以后会和python, java进行横向，咱还是挑相对快一点的好～  不过话说回来，再怎么的精挑细选，java那边还是基本没有悬念，真正有悬念的，我们都心知肚明，呵呵。</p>
<p>所以真正运动之前先来点热身运动，看看哪个循环在我这相对要快：</p>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'benchmark'</span><br />
<br />
n = ARGV.<span style="color:#9900CC;">empty</span>? ? <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">**</span> <span style="color:#006666;">6</span> : <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">**</span> ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;n=#{n}&quot;</span><br />
<span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bmbm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>b<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; b.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;for:&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#9966CC; font-weight:bold;">for</span> i <span style="color:#9966CC; font-weight:bold;">in</span> 1..<span style="color:#9900CC;">n</span> &nbsp;; a = <span style="color:#996600;">&quot;0&quot;</span>; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; b.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;times:&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp;<span style="color:#006600; font-weight:bold;">&#123;</span> n.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span> &nbsp; &nbsp; ; a = <span style="color:#996600;">&quot;0&quot;</span>; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; b.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;upto:&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> 1.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> &nbsp; ; a = <span style="color:#996600;">&quot;0&quot;</span>; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; b.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;downto:&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> n.<span style="color:#9900CC;">downto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> ; a = <span style="color:#996600;">&quot;0&quot;</span>; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>以上是我所想到的比较常见的4种茴字写法，程序默认取n=10^6进行循环，也可以接受一个作为幂指数的命令行参数，Benchmark的bmbm方法会先dry run一遍所有test作为rehearsal，等memory和garbage collection的状态相对stable了以后才进行真正的benchmark，这样先运行和后运行的report会相对公平一点。</p>
<p>默认运行（ n=10^6 ）的结果如下：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">n</span>=<span style="color: #000000;">1000000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.310000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.310000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.313392</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.290000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.290000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.297268</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.300000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.300000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.300311</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.310000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.310000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.304146</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 1.210000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.310000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.310000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.313129</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.290000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.290000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.297470</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.300000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.300000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.302154</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.310000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.310000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.305562</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></div></div>
<p>一次完整运行（ n=10~10^8 ）的数据结果如下：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">n</span>=<span style="color: #000000;">10</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000018</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000011</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000047</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000053</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000014</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000011</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000011</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000011</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000041</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000031</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000033</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000040</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000035</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000030</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000031</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000031</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">1000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000367</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000315</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000319</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000854</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000273</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000250</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000254</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000258</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">10000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003388</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003056</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003006</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003084</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.010000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003114</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.002955</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003047</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.004650</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.032892</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.029808</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.031190</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.030379</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.120000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.033382</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.029139</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.031608</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.030498</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">1000000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.310000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.310000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.313392</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.290000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.290000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.297268</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.300000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.300000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.300311</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.310000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.310000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.304146</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 1.210000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.310000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.310000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.313129</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.290000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.290000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.297470</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.300000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.300000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.302154</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.310000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.310000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.305562</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">10000000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">3.090000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">3.090000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.109693</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">2.940000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">2.950000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">2.946662</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">2.990000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">3.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.003812</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">3.010000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">3.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.021900</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------------</span> total: 12.050000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">3.110000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">3.120000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.119928</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">2.950000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">2.960000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">2.992141</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">3.000000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">3.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.044853</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">3.020000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">3.020000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.036987</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100000000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; <span style="color: #000000;">30.950000</span> &nbsp; <span style="color: #000000;">0.070000</span> &nbsp;<span style="color: #000000;">31.020000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">31.139756</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; <span style="color: #000000;">29.360000</span> &nbsp; <span style="color: #000000;">0.060000</span> &nbsp;<span style="color: #000000;">29.420000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">29.543839</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp;<span style="color: #000000;">29.890000</span> &nbsp; <span style="color: #000000;">0.070000</span> &nbsp;<span style="color: #000000;">29.960000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">30.102346</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp;<span style="color: #000000;">30.080000</span> &nbsp; <span style="color: #000000;">0.070000</span> &nbsp;<span style="color: #000000;">30.150000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">30.271642</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">--------------------------------</span> total: 120.550000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; <span style="color: #000000;">31.130000</span> &nbsp; <span style="color: #000000;">0.080000</span> &nbsp;<span style="color: #000000;">31.210000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">31.359814</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; <span style="color: #000000;">29.420000</span> &nbsp; <span style="color: #000000;">0.050000</span> &nbsp;<span style="color: #000000;">29.470000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">29.630556</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp;<span style="color: #000000;">30.050000</span> &nbsp; <span style="color: #000000;">0.060000</span> &nbsp;<span style="color: #000000;">30.110000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">30.197589</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp;<span style="color: #000000;">30.180000</span> &nbsp; <span style="color: #000000;">0.050000</span> &nbsp;<span style="color: #000000;">30.230000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">30.361343</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================</div></div>
<p>由于精力有限，就不做多次运行取平均值这种相对无聊的事情了，结果虽然不严谨也无法真正判断出究竟谁最快（times和upto，downto是在伯仲之间），但至少可以看出for in range是相对最慢的。</p>
<p>换ruby1.9后的运行结果与上基本一致，详细数据如下：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">n</span>=<span style="color: #000000;">10</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000029</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000050</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000014</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000013</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000014</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000011</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000012</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000012</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000061</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000103</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000078</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000060</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000066</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000061</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000061</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000061</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">1000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000465</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000461</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000477</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000428</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000388</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000339</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000341</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.000339</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">10000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.004486</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003675</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.004407</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.004121</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.010000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003961</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.005113</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.010000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003592</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.000000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.003592</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.040000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.040000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.042573</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.039094</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.030000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.041495</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.040000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.040000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.049316</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 0.140000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.040000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.040000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.040422</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.040000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.040000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.037030</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.040000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.040000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.041921</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.040000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.040000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.039868</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">1000000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.390000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.390000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.401887</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.370000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.370000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.376656</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.370000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.380000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.384750</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.370000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.370000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.380184</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">----------------------------------</span> total: 1.510000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0.400000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.400000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.411929</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">0.370000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.370000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.386443</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">0.370000</span> &nbsp; <span style="color: #000000;">0.010000</span> &nbsp; <span style="color: #000000;">0.380000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.379820</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">0.370000</span> &nbsp; <span style="color: #000000;">0.000000</span> &nbsp; <span style="color: #000000;">0.370000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">0.379068</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">10000000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">3.920000</span> &nbsp; <span style="color: #000000;">0.020000</span> &nbsp; <span style="color: #000000;">3.940000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">4.021434</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">3.690000</span> &nbsp; <span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">3.720000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.844118</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">3.710000</span> &nbsp; <span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">3.740000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.844035</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">3.700000</span> &nbsp; <span style="color: #000000;">0.020000</span> &nbsp; <span style="color: #000000;">3.720000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.795330</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">---------------------------------</span> total: 15.120000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; &nbsp;<span style="color: #000000;">3.910000</span> &nbsp; <span style="color: #000000;">0.020000</span> &nbsp; <span style="color: #000000;">3.930000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">4.003016</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; &nbsp;<span style="color: #000000;">3.670000</span> &nbsp; <span style="color: #000000;">0.020000</span> &nbsp; <span style="color: #000000;">3.690000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.749495</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp; <span style="color: #000000;">3.700000</span> &nbsp; <span style="color: #000000;">0.020000</span> &nbsp; <span style="color: #000000;">3.720000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.919785</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp; <span style="color: #000000;">3.690000</span> &nbsp; <span style="color: #000000;">0.030000</span> &nbsp; <span style="color: #000000;">3.720000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> &nbsp;<span style="color: #000000;">3.789975</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================<br />
<br />
<span style="color: #007800;">n</span>=<span style="color: #000000;">100000000</span><br />
Rehearsal <span style="color: #660033;">-------------------------------------------</span><br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; <span style="color: #000000;">39.260000</span> &nbsp; <span style="color: #000000;">0.240000</span> &nbsp;<span style="color: #000000;">39.500000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">40.293460</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; <span style="color: #000000;">36.700000</span> &nbsp; <span style="color: #000000;">0.210000</span> &nbsp;<span style="color: #000000;">36.910000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">37.450910</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp;<span style="color: #000000;">37.020000</span> &nbsp; <span style="color: #000000;">0.260000</span> &nbsp;<span style="color: #000000;">37.280000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">38.963391</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp;<span style="color: #000000;">36.940000</span> &nbsp; <span style="color: #000000;">0.230000</span> &nbsp;<span style="color: #000000;">37.170000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">37.806189</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">--------------------------------</span> total: 150.860000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
<span style="color: #000000; font-weight: bold;">for</span>: &nbsp; &nbsp; <span style="color: #000000;">39.230000</span> &nbsp; <span style="color: #000000;">0.240000</span> &nbsp;<span style="color: #000000;">39.470000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">40.471694</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">times</span>: &nbsp; <span style="color: #000000;">36.850000</span> &nbsp; <span style="color: #000000;">0.240000</span> &nbsp;<span style="color: #000000;">37.090000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">38.302817</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
upto: &nbsp; &nbsp;<span style="color: #000000;">36.870000</span> &nbsp; <span style="color: #000000;">0.230000</span> &nbsp;<span style="color: #000000;">37.100000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">37.802815</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
downto: &nbsp;<span style="color: #000000;">36.970000</span> &nbsp; <span style="color: #000000;">0.220000</span> &nbsp;<span style="color: #000000;">37.190000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">38.052300</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
=====================================================</div></div>
<p>有趣的是ruby1.9的循环操作性能竟然普遍都是负增长，这倒为我们之后的list performance比较埋下了伏笔。</p>
<p>热身运动到此结束，似乎有喧宾夺主之嫌，所以赶紧搞个part 2…，下篇文章我们会用上面循环性能测试的疑似最佳表现者times来进行list append性能测试，敬请期待。</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-2/" title="List performance: ruby 1.8 and 1.9 (Part 2) (February 22, 2010)">List performance: ruby 1.8 and 1.9 (Part 2)</a> (17)</li>
	<li><a href="http://blog.samsonis.me/2011/02/rubygems-1-5-2-manual-upgrade/" title="RubyGems 1.5.2 Manual Upgrade (February 16, 2011)">RubyGems 1.5.2 Manual Upgrade</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/" title="ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221; (February 21, 2010)">ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221;</a> (2)</li>
	<li><a href="http://blog.samsonis.me/2010/02/ruby-gem-geoip-and-rack-geoipcountry/" title="Ruby gem geoip and Rack::GeoIPCountry (February 25, 2010)">Ruby gem geoip and Rack::GeoIPCountry</a> (2)</li>
	<li><a href="http://blog.samsonis.me/2011/12/downgrade-rubygems/" title="Downgrade Rubygems (December 5, 2011)">Downgrade Rubygems</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2010/02/list-performance-ruby-1-8-and-1-9-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

