require 'benchmark'
times = 200000
Benchmark.bm do |x|
strings = []
100.times do
strings << "abcd"
end
numbers = []
100.times do
numbers << 123
end
x.report "dup strings" do
i = 0
while i < times
strings.dup
i += 1
end
end
x.report "dup numbers" do
i = 0
while i < times
numbers.dup
i += 1
end
end
end
require 'benchmark'
times = 100000
Benchmark.bm do |x|
strings = []
100.times do
strings << "abcd"
end
x.report do
i = 0
while i < times
strings.sort
i += 1
end
end
end
* before
- bm_ary_dup.rb
user system total real
dup strings 2.150000 0.070000 2.220000 ( 1.854919)
dup numbers 0.460000 0.070000 0.530000 ( 0.294771)
- bm_ary_sort.rb
user system total real
2.130000 0.030000 2.160000 ( 1.970458)
* after
- bm_ary_dup.rb
user system total real
dup strings 0.970000 0.090000 1.060000 ( 0.585213)
dup numbers 0.500000 0.080000 0.580000 ( 0.311979)
- bm_ary_sort.rb
user system total real
1.330000 0.030000 1.360000 ( 1.183701)