add benchmark for Symbol

This commit is contained in:
Watson
2014-01-27 09:56:13 +09:00
parent f11dd74200
commit e83e74eba9
5 changed files with 27 additions and 0 deletions

View File

@@ -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 }

View File

@@ -14,6 +14,7 @@ def bm_string
string_split(x)
string_to_f(x)
string_to_i(x)
string_to_sym(x)
end
end

View 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

View File

@@ -0,0 +1,5 @@
def bm_symbol
Benchmark.benchmark("", 30, "%r\n") do |x|
symbol_to_s(x)
end
end

View 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