<?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/tag/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>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>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>
		<item>
		<title>ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221;</title>
		<link>http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/</link>
		<comments>http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 18:57:43 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Minds]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[SimpleHTTPServer]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=1555</guid>
		<description><![CDATA[If I remembered right, the command below used to be the most voted one on commandlinefu.com: $ python -m SimpleHTTPServer the &#8220;SimpleHTTPServer&#8221; module is written in python and it maybe called &#8220;the python way&#8221;, but that&#8217;s not our topic today. what we really want to do here is just making a ruby equivalent for this ...]]></description>
			<content:encoded><![CDATA[<p>If I remembered right, the command below used to be the most voted one on <a href="http://www.commandlinefu.com/">commandlinefu.com</a>:</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">$ python <span style="color: #660033;">-m</span> SimpleHTTPServer</div></div>
<p>the &#8220;SimpleHTTPServer&#8221; module is written in python and it maybe called &#8220;the python way&#8221;, but that&#8217;s not our topic today.  what we really want to do here is just making a ruby equivalent for this popular command, using <a href="http://rack.rubyforge.org/">rack</a>.</p>
<p>first, make sure you have rack gem installed on your system (if you&#8217;ve installed rails 2.x before, you may already have it):</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> rack</div></div>
<p>confirm installation (Rack 1.0 should also work for our example):</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">$ rackup <span style="color: #660033;">--version</span><br />
Rack <span style="color: #000000;">1.1</span></div></div>
<p>alright, preparation is done, let&#8217;s start cooking.  only a rackup file will be sufficient, for consistency, let&#8217;s just call it simple_http_server.ru .</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:#008000; font-style:italic;">#!/usr/bin/env rackup</span><br />
<span style="color:#008000; font-style:italic;">#\ -E deployment</span><br />
<br />
use <span style="color:#6666ff; font-weight:bold;">Rack::ContentLength</span><br />
<br />
app = <span style="color:#6666ff; font-weight:bold;">Rack::Directory</span>.<span style="color:#9900CC;">new</span> <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">pwd</span><br />
run app</div></div>
<p><span id="more-1555"></span><br />
Rack::Directory is so awesome that we just simply rely on it&#8230; aren&#8217;t i cheating?  hehe, maybe&#8230;</p>
<p>ok, we&#8217;re done. to test it, simply run:</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">$ rackup simple_http_server.ru</div></div>
<p>and then point your browser to http://locahost:9292/ .</p>
<p><a href="http://blog.samsonis.me/wp-content/uploads/2010/02/simple-http-server.png"><img src="http://blog.samsonis.me/wp-content/uploads/2010/02/simple-http-server-300x218.png" alt="" title="simple-http-server" width="300" height="218" class="alignnone size-medium wp-image-1594" /></a></p>
<p>to be useful for daily use, you may consider chmod +x it to make it executable and put it in your $PATH.</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;">chmod</span> +x simple_http_server.ru<br />
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span></div></div>
<p>to share a directory with your coworkers or friends, simply cd to that directory and execute the script:</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;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>the<span style="color: #000000; font-weight: bold;">/</span>dir<span style="color: #000000; font-weight: bold;">/</span>i<span style="color: #000000; font-weight: bold;">/</span>want<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>share<br />
$ simple_http_server.ru</div></div>
<p>since we&#8217;re actually using rackup to execute, all the rackup options are also available, which is 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">$ simple_http_server.ru <span style="color: #660033;">-h</span></div></div>
<p>finally, let&#8217;s end up with emulating python SimpleHTTPServer&#8217;s default behavior:</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">$ simple_http_server.ru <span style="color: #660033;">-p</span> <span style="color: #000000;">8000</span></div></div>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<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/2009/02/%e5%87%86%e5%a4%87%e5%ad%a6%e4%b9%a0python%e5%92%8cphp/" title="准备学习Python和PHP (February 15, 2009)">准备学习Python和PHP</a> (14)</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/2011/08/python-nameerror-name-readline-is-not-defined/" title="Python NameError: name &#8216;readline&#8217; is not defined (August 16, 2011)">Python NameError: name &#8216;readline&#8217; is not defined</a> (3)</li>
	<li><a href="http://blog.samsonis.me/2009/02/python-2x-or-30/" title="Python 2.x or 3.0 (February 17, 2009)">Python 2.x or 3.0</a> (4)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

