From: Yusuke ENDOH Date: 2010-03-07T05:44:02+09:00 Subject: [ruby-core:28539] Re: [Feature #905] Add String.new(fixnum) to preallocate large buffer Hi, 2010/3/6 Kornelius Kalnbach : > Here's a patch that doesn't work. I don't know what I'm doing wrong here: RESIZE_CAPA seemed just right. Thank you for your writing a patch! It seems to work on my environment. What made you think it does not work? I confirmed it by the following program: opt = false s = "" t = "x" * 1_000_000 s.buffer(100_000_000) if opt 100.times { s << t } p s.size The above program takes 0.205 sec. when opt is false, and takes 0.195 sec. when opt is true. But this is artificial example with very big string (1 GB). The following more realistic case (with 100 KB): opt = false 1000.times do s = "" s.buffer(opt ? 100_001 : 100) x = "x" * 1000 100.times { s << x } end takes 0.115 sec. when opt is false, 0.130 sec. when opt is true. I don't know why it becomes slower, but the story seems not to be so simple. Anyway, the overhead of concatenation seems not so big. I doubt if it is the bottleneck. -- Yusuke ENDOH