G
Gavin
Hey all
I was always under the impression that parallel assignments in Ruby
were faster than assigning variables individually.
Recently I was curious to see how much faster it was and decided to
test it:
class One
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
end
class Two
def initialize(first_name, last_name)
@first_name, @last_name = first_name, last_name
end
end
require "rubygems"
require "benchmark"
Benchmark.bmbm do |test|
test.report("serial") do
10000.times { |n| var = One.new("gavin#{n}", "morrice")}
end
test.report("parallel") do
10000.times { |n| var = Two.new("gavin#{n}", "morrice")}
end
end
The results I get show that it's slower (in both Ruby 1.8.7 and Ruby
1.9.1)
Can anyone elaborate?
Thanks
I was always under the impression that parallel assignments in Ruby
were faster than assigning variables individually.
Recently I was curious to see how much faster it was and decided to
test it:
class One
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
end
class Two
def initialize(first_name, last_name)
@first_name, @last_name = first_name, last_name
end
end
require "rubygems"
require "benchmark"
Benchmark.bmbm do |test|
test.report("serial") do
10000.times { |n| var = One.new("gavin#{n}", "morrice")}
end
test.report("parallel") do
10000.times { |n| var = Two.new("gavin#{n}", "morrice")}
end
end
The results I get show that it's slower (in both Ruby 1.8.7 and Ruby
1.9.1)
Can anyone elaborate?
Thanks