# -*- coding: utf-8 -*-
require 'benchmark'
Benchmark.bm(10) do |x|
if (Kernel.const_defined?(:MACRUBY_VERSION))
str_utf16 = "abcdefg0123456789\n".force_encoding('UTF-16LE') * 10000
x.report "UTF-16" do
str_utf16.split("\n".force_encoding('UTF-16LE'))
end
end
str_utf8 = "abcdefg0123456789\n" * 10000
x.report "UTF-8" do
str_utf8.split("\n")
end
end
$ macruby bm_split.rb
user system total real
UTF-16 0.000000 0.000000 0.000000 ( 0.001054)
UTF-8 0.010000 0.010000 0.020000 ( 0.010342)
$ ruby19 bm_split.rb
user system total real
UTF-8 0.010000 0.000000 0.010000 ( 0.001824)