Created
February 18, 2015 08:05
-
-
Save hatyuki/9992b00ac56e0b69dc32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
N = 1000000 | |
string = '' | |
Benchmark.bm(11) do |x| | |
100.times do |digits| | |
string << rand(10).to_s | |
fixnum = string.to_i | |
symbol = string.to_sym | |
i = digits + 1 | |
x.report %Q!#{i} digits Fixnum#to_s! do | |
(1..N).each { fixnum.to_s } | |
end | |
x.report %Q!#{i} digits "\#{Fixnum}"! do | |
(1..N).each { "#{fixnum}" } | |
end | |
x.report %Q!#{i} digits Symbol#to_s! do | |
(1..N).each { symbol.to_s } | |
end | |
x.report %Q!#{i} digits "\#{Symbol}"! do | |
(1..N).each { "#{symbol}" } | |
end | |
x.report %Q!#{i} digits String#to_s! do | |
(1..N).each { string.to_s } | |
end | |
x.report %Q!#{i} digits "\#{String}"! do | |
(1..N).each { "#{string}" } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment