Reduce needless Array generation in some String methods
Here are some benchmarks: each_char: # /tmp/each_char.rb a = "a" * 1000000 a.each_char do |x| end Without this change: % time bin/mruby /tmp/each_char.rb bin/mruby /tmp/each_char.rb 1.07s user 0.02s system 99% cpu 1.088 total With this change: % time bin/mruby /tmp/each_char.rb bin/mruby /tmp/each_char.rb 0.52s user 0.01s system 99% cpu 0.530 total 2 times faster with this change. codepoints: # /tmp/codepoints.rb a = "a" * 1000000 a.codepoints do |x| end Without this change: % time bin/mruby /tmp/codepoints.rb bin/mruby /tmp/codepoints.rb 1.16s user 0.05s system 99% cpu 1.216 total With this change: % time bin/mruby /tmp/codepoints.rb bin/mruby /tmp/codepoints.rb 0.56s user 0.02s system 99% cpu 0.589 total
Showing
Please register or sign in to comment