#1077: Performance of String ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by yasuimao@…): As suggested, I added .force_encoding("UTF-16BE") and run the test with 2011/01/05 nightly. {{{ freq = Hash.new(0) 10.times{File.read("test.txt").force_encoding("UTF- 16BE").scan(/\w+/){|word| freq[word] += 1}} }}} '''Results''' {{{ MacRuby 0.9 2011/01/05 1548 words - 0.082 0.092 0.081 8092 words - 0.43 0.44 0.47 }}} Now it is slightly faster than 0.8 (or 0.9 2010/12/17 nightly), though it's still twice as slow as 1.8.7. I also tested this with NSString#stringWithContentsOfFile:encoding:error: {{{ freq = Hash.new(0) 10.times{NSString.stringWithContentsOfFile("test.txt",encoding: NSUTF8StringEncoding, error: nil).scan(/\w+/){|word| freq[word] += 1}} }}} '''Results''' {{{ MacRuby 0.9 2011/01/05 1548 words - 1.39 1.38 1.42 8092 words - 34.81 34.47 34.54 }}} By applying force_encoding, this process also took less time. {{{ freq = Hash.new(0) 10.times{NSString.stringWithContentsOfFile("test.txt",encoding: NSUTF8StringEncoding, error: nil).UTF8String.force_encoding("UTF- 16BE").scan(/\w+/){|word| freq[word] += 1}} }}} '''Results''' {{{ MacRuby 0.9 2011/01/05 1548 words - 0.096 0.084 0.081 8092 words - 0.42 0.42 0.45 }}} This workaround works, but it would be desirable not to have to add extra methods. -- Ticket URL: <http://www.macruby.org/trac/ticket/1077#comment:7> MacRuby <http://macruby.org/>