Samson’s Weblog

Tag: Performance

List performance: ruby 1.8 and 1.9 (Part 2)

by Samson on Feb.22, 2010, under Ruby, Technique

接上篇: List performance: ruby 1.8 and 1.9 (Part 1)

有了之前的准备和热身,真正跑起步来似乎轻松不少,先贴上我们用来benchmark的code:

require 'benchmark'

n = ARGV.empty? ? 10 ** 6 : 10 ** ARGV[0].to_i
puts "n=#{n}"
Benchmark.bmbm do |x|
  x.report do
    list = []
    n.times do
      list < < 0
    end
  end
end

之前用来benchmark loop performance的code结构上基本没有区别,这里不再赘述,具体的解释亦可参照前文。
(continue reading…)

17 Comments :, more...

List performance: ruby 1.8 and 1.9 (Part 1)

by Samson on Feb.22, 2010, under Ruby, Technique

(本文数据较多,在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 (2009-06-12 patchlevel 174) [i686-darwin9]
$ ruby1.9 -v
ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin9]

还有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

(continue reading…)

Leave a Comment :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!