mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-01 17:39:54 +08:00
add a benchmark for string concatenation because CRuby has special optimization for short string
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
def string_concat(x)
|
||||
ascii = "hello"
|
||||
utf8 = "こんにちは"
|
||||
long_string = "The quick brown fox jumps over the lazy dog."
|
||||
|
||||
x.report "interpolation with ASCII" do
|
||||
100000.times do
|
||||
@@ -14,6 +15,12 @@ def string_concat(x)
|
||||
end
|
||||
end
|
||||
|
||||
x.report "interpolation with long" do
|
||||
100000.times do
|
||||
"#{long_string} #{long_string} #{long_string}"
|
||||
end
|
||||
end
|
||||
|
||||
x.report "+ with ASCII" do
|
||||
100000.times do
|
||||
ascii + ascii + ascii
|
||||
@@ -26,6 +33,12 @@ def string_concat(x)
|
||||
end
|
||||
end
|
||||
|
||||
x.report "+ with long" do
|
||||
100000.times do
|
||||
long_string + long_string + long_string
|
||||
end
|
||||
end
|
||||
|
||||
x.report "<< with ASCII" do
|
||||
100000.times do
|
||||
str = ascii.dup
|
||||
@@ -40,6 +53,13 @@ def string_concat(x)
|
||||
end
|
||||
end
|
||||
|
||||
x.report "<< with long" do
|
||||
100000.times do
|
||||
str = long_string.dup
|
||||
str << str << str
|
||||
end
|
||||
end
|
||||
|
||||
x.report "concat with ASCII" do
|
||||
100000.times do
|
||||
str = ascii.dup
|
||||
@@ -54,6 +74,13 @@ def string_concat(x)
|
||||
end
|
||||
end
|
||||
|
||||
x.report "concat with long" do
|
||||
100000.times do
|
||||
str = long_string.dup
|
||||
str.concat(str).concat(str)
|
||||
end
|
||||
end
|
||||
|
||||
x.report "* with ASCII" do
|
||||
100000.times do
|
||||
ascii * 10
|
||||
@@ -65,4 +92,10 @@ def string_concat(x)
|
||||
utf8 * 10
|
||||
end
|
||||
end
|
||||
|
||||
x.report "* with long" do
|
||||
100000.times do
|
||||
long_string * 10
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user