Issue #7210 has been reported by bowen113 (bowen wenqi).

----------------------------------------
Bug #7210: Exponential performance when summing Enumerable
https://bugs.ruby-lang.org/issues/7210

Author: bowen113 (bowen wenqi)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: 
Target version: 2.0.0
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]


=begin
When you sum an Enumerable (using .inject(:+) or in a more verbose fashion), 1.8.7 and 1.9.2 show exponential performance, where JRuby and Rubinius show the expected linear behavior. 

class A
  attr_accessor :foo
  def initialize(foo)
    @foo = foo
  end

  def +(other)
    A.new(self.foo + other.foo)
  end
end

(10..15).each do |factor|
  start = Time.now
  ([A.new(2)] * 2**factor * 100).inject(:+)
  puts "#{2**factor * 100} took #{(Time.now - start)} s."
end

Outcomes (I'm not interested in the absolute timings: note the factors between each step):
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03

 102400 took 0.151034 s.
 204800 took 0.345033 s.
 409600 took 0.920415 s.
 819200 took 2.086751 s.
1638400 took 5.727894 s.
3276800 took 18.041329 s.

ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
 102400 took 0.074562689 s.
 204800 took 0.164413421 s.
 409600 took 0.44690715 s.
 819200 took 1.458326897 s.
1638400 took 3.215625728 s.
3276800 took 9.992734203 s.

jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2010-12-03 9cf97c3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20) [amd64-java]
 102400 took 0.705 s.
 204800 took 0.206 s.
 409600 took 0.222 s.
 819200 took 0.37 s.
1638400 took 0.777 s.
3276800 took 1.441 s.

rubinius 1.2.4dev (1.8.7 9d6719d4 yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]
 102400 took 0.132361 s.
 204800 took 0.138144 s.
 409600 took 0.324924 s.
 819200 took 0.54765 s.
1638400 took 1.0541179999999999 s.
3276800 took 2.2074 s.
<a href="http://www.celine-bag-sale.com/" target="_blank">celine bags</a>
<a href="http://www.celine-bag-sale.com/celine-clutch-bags-c-87.html" target="_blank">celine clutch bags</a>
[http://www.celine-bag-sale.com celine bags]


=end



-- 
http://bugs.ruby-lang.org/