From: Motohiro KOSAKI Date: 2010-03-07T20:46:18+09:00 Subject: [ruby-core:28547] [Feature #905] Add String.new(fixnum) to preallocate large buffer Issue #905 has been updated by Motohiro KOSAKI. >$ cat test.rb >require 'benchmark' >opt = ARGV[0] >list = Array.new(10) do > Benchmark.realtime do > 1000.times do > s = "" > s.buffer(opt ? 100_001 : 100) > x = "x" * 1000 > 100.times { s << x } > end > end >end >list.sort! >p list.first, list.last > >$ ./ruby -v -Ilib test.rb opt >ruby 1.9.2dev (2010-03-07 trunk 26843) [i386-mingw32] >0.1780099868774414 >0.18601107597351074 > >$ ./ruby -v -Ilib test.rb >ruby 1.9.2dev (2010-03-07 trunk 26843) [i386-mingw32] >0.21401190757751465 >0.22301316261291504 Ah, yes. "x" * 1000 is not so big string. then, its realloc() doesn't use mremap. It mean string concat(i.e. "<<" operator) cause string copy on each time. but is this real issue? Does small string copy makes big peformance issue? when? So, I think we need good realistic benchmark. Thanks. ---------------------------------------- http://redmine.ruby-lang.org/issues/show/905 ---------------------------------------- http://redmine.ruby-lang.org