mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-01 09:31:20 +08:00
add benchmark for Symbol
This commit is contained in:
@@ -25,6 +25,9 @@ autorelease_pool { bm_range }
|
||||
puts "*** String ***"
|
||||
autorelease_pool { bm_string }
|
||||
|
||||
puts "*** Symbol ***"
|
||||
autorelease_pool { bm_symbol }
|
||||
|
||||
puts "*** Time ***"
|
||||
autorelease_pool { bm_time }
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ def bm_string
|
||||
string_split(x)
|
||||
string_to_f(x)
|
||||
string_to_i(x)
|
||||
string_to_sym(x)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
9
test/Benchmark/app/benchmark/string/to_sym.rb
Normal file
9
test/Benchmark/app/benchmark/string/to_sym.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
def string_to_sym(x)
|
||||
string = "x" * 30
|
||||
|
||||
x.report "to_sym" do
|
||||
1000000.times do
|
||||
string.to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
5
test/Benchmark/app/benchmark/symbol.rb
Normal file
5
test/Benchmark/app/benchmark/symbol.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
def bm_symbol
|
||||
Benchmark.benchmark("", 30, "%r\n") do |x|
|
||||
symbol_to_s(x)
|
||||
end
|
||||
end
|
||||
9
test/Benchmark/app/benchmark/symbol/to_s.rb
Normal file
9
test/Benchmark/app/benchmark/symbol/to_s.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
def symbol_to_s(x)
|
||||
symbol = :"hello world"
|
||||
|
||||
x.report "to_s" do
|
||||
1000000.times do
|
||||
symbol.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user