#1019: String#gsub performance ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by yasuimao@…): With 2011/01/05, the test results are the same. {{{ MacRuby 0.9 2011/01/05 nightly - 8092 words Test 1 - 34.35 seconds Test 2 - 69.64 seconds }}} With force_encoding, this process took much less time than 0.8 and only slightly slower than 1.8.7. Test 1 - gsub {{{ 10.times{File.read("test.txt").force_encoding("UTF- 16BE").gsub!(/\w+/,"test".force_encoding("UTF-16BE"))} }}} Test 2 - gsub with block {{{ 10.times{File.read("test.txt").force_encoding("UTF-16BE").gsub!(/\w+/){|x| x.upcase}} }}} '''Results''' {{{ MacRuby 0.9 2011/01/05 nightly - 8092 words with force_encoding Test 1 - 0.16 seconds Test 2 - 0.40 seconds }}} The problem of this is that the script file should also be encoded in UTF- 16BE unless adding force_encode (or encode) to each string object created in the script. (or is there a better way?) -- Ticket URL: <http://www.macruby.org/trac/ticket/1019#comment:6> MacRuby <http://macruby.org/>