List performance: ruby 1.8 and 1.9 (Part 2)

接上篇: List performance: ruby 1.8 and 1.9 (Part 1) 有了之前的准备和热身,真正跑起步来似乎轻松不少,先贴上我们用来benchmark的code: [cc lang=”ruby”] 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 [/cc] 和之前用来benchmark loop performance的code结构上基本没有区别,这里不再赘述,具体的解释亦可参照前文。 下面分别是ruby 1.8和ruby 1.9的一次完整运行( n=10~10^8 )的数据结果(也是我唯一运行的一次…) ruby 1.8: [cc lang=”bash”] n=10 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000014) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000012) ============================================== n=100 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000118) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000061) ============================================== n=1000 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000375) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000314) ============================================== n=10000 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.002900) ————————— total: 0.000000sec user system total real 0.010000 0.000000 0.010000 ( 0.002790) ============================================== n=100000 Rehearsal ———————————— 0.030000 0.000000 0.030000 ( 0.027712) ————————— total: 0.030000sec user system total real 0.020000 0.000000 0.020000 ( 0.027713) ============================================== n=1000000 Rehearsal ———————————— 0.280000 0.010000 0.290000 ( 0.323298) ————————— total: 0.290000sec user system total real 0.280000 0.010000 0.290000 ( 0.283621) ============================================== n=10000000 Rehearsal ———————————— 2.740000 0.050000 2.790000 ( 2.809917) ————————— total: 2.790000sec user system total real 2.760000 0.040000 2.800000 ( 2.810491) ============================================== n=100000000 Rehearsal ———————————— 27.410000 0.490000 27.900000 ( 28.164103) ————————– total: 27.900000sec user system total real 27.620000 0.480000 28.100000 ( 28.230073) ============================================== [/cc] ruby 1.9: [cc lang=”bash”] n=10 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000068) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000012) ============================================== n=100 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000038) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000032) ============================================== n=1000 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000297) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000209) ============================================== n=10000 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.002164) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.002025) ============================================== n=100000 Rehearsal ———————————— 0.020000 0.000000 0.020000 ( 0.020366) ————————— total: 0.020000sec user system total real 0.020000 0.000000 0.020000 ( 0.020873) ============================================== n=1000000 Rehearsal ———————————— 0.190000 0.010000 0.200000 ( 0.208302) ————————— total: 0.200000sec user system total real 0.190000 0.000000 0.190000 ( 0.208822) ============================================== n=10000000 Rehearsal ———————————— 1.920000 0.050000 1.970000 ( 2.050276) ————————— total: 1.970000sec user system total real 1.920000 0.050000 1.970000 ( 2.054335) ============================================== n=100000000 Rehearsal ———————————— 19.220000 0.460000 19.680000 ( 20.466960) ————————– total: 19.680000sec user system total real 19.220000 0.460000 19.680000 ( 20.546417) ============================================== [/cc] 就这次运行的结果而言,ruby 1.9的performance平均都有25%~35%的提升,加之Part 1测试过的循环性能的倒退,则更可以确定list append操作的performance确实在1.9里面较1.8有了很大的提高。

Buy me a coffee
  • Post author: Samson Wu
  • Post link: 1654.html
  • Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.
0%