[#28687] [Bug #2973] rb_bug - Segmentation fault - error.c:213 — rudolf gavlas <redmine@...>

Bug #2973: rb_bug - Segmentation fault - error.c:213

10 messages 2010/03/16

[#28735] [Bug #2982] Ruby tries to link with both openssl and readline — Lucas Nussbaum <redmine@...>

Bug #2982: Ruby tries to link with both openssl and readline

16 messages 2010/03/18

[#28736] [Bug #2983] Ruby (GPLv2 only) tries to link to with readline (now GPLv3) — Lucas Nussbaum <redmine@...>

Bug #2983: Ruby (GPLv2 only) tries to link to with readline (now GPLv3)

10 messages 2010/03/18

[#28907] [Bug #3000] Open SSL Segfaults — Christian Höltje <redmine@...>

Bug #3000: Open SSL Segfaults

19 messages 2010/03/23

[#28924] [Bug #3005] Ruby core dump - [BUG] rb_sys_fail() - errno == 0 — Sebastian YEPES <redmine@...>

Bug #3005: Ruby core dump - [BUG] rb_sys_fail() - errno == 0

10 messages 2010/03/24

[#28954] [Feature #3010] slow require gems in ruby 1.9.1 — Miao Jiang <redmine@...>

Feature #3010: slow require gems in ruby 1.9.1

15 messages 2010/03/24

[#29179] [Bug #3071] Convert rubygems and rdoc to use psych — Aaron Patterson <redmine@...>

Bug #3071: Convert rubygems and rdoc to use psych

10 messages 2010/03/31

[ruby-core:28546] Re: [Feature #905] Add String.new(fixnum) to preallocate large buffer

From: Yusuke ENDOH <mame@...>
Date: 2010-03-07 10:58:38 UTC
List: ruby-core #28546
Hi,

2010/3/5 Kornelius Kalnbach <murphy@rubychan.de>:
> JRuby, for example,
> concats strings almost twice as fast in this benchmark:
>
> require 'benchmark'
>
> N = 10_000_000
> Benchmark.bm 20 do |results|
>  results.report 'loop' do
>    N.times { }
>  end
>  results.report "'' <<" do
>    s = ''
>    N.times { s << '.' << 'word' }
>  end
> end
>
> ruby19 string_buffer.rb
>                          user     system      total        real
> loop                  1.240000   0.010000   1.250000 (  1.255154)
> '' <<                 5.820000   0.060000   5.880000 (  5.889959)
>
> jruby string_buffer.rb
>                          user     system      total        real
> loop                  0.584000   0.000000   0.584000 (  0.488000)
> '' <<                 2.900000   0.000000   2.900000 (  2.900000)


I wonder why such a simple loop is slower than jruby...?

I retested.

  ruby19
                            user     system      total        real
  loop                  2.100000   0.000000   2.100000 (  2.095623)
  '' <<                11.720000   0.040000  11.760000 ( 11.768111)

  jruby
                            user     system      total        real
  loop                  2.263000   0.000000   2.263000 (  2.228000)
  '' <<                10.193000   0.000000  10.193000 ( 10.193000)

Ko1 told me that GC makes the second benchmark slower than JRuby.
In MRI, a string literal is duplicated whenever evaluated.
I moved the literals out of the loop:

  results.report "'' <<" do
    s = ''
    s1, s2 = '.', 'word'
    N.times { s << s1 << s2 }
  end

  ruby19
                            user     system      total        real
  '' <<                 6.810000   0.040000   6.850000 (  6.851979)

  jruby
                            user     system      total        real
  '' <<                 7.159000   0.000000   7.159000 (  7.126000)

Indeed, there is room for optimization in MRI, but in this case,
it is not in string concatenation, I guess.

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread