Skip to content

Instantly share code, notes, and snippets.

@raggi
Created August 4, 2009 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raggi/162162 to your computer and use it in GitHub Desktop.
Save raggi/162162 to your computer and use it in GitHub Desktop.
require 'benchmark'
def many
10000
end
def push(left_array_size, right_array_size)
left = Array.new(left_array_size) { |n| n }
right = Array.new(right_array_size) { |n| n }
Benchmark.realtime{ many.times{ |i| left.push(*right) } }
end
def concat(left_array_size, right_array_size)
left = Array.new(left_array_size) { |n| n }
right = Array.new(right_array_size) { |n| n }
Benchmark.realtime{ many.times{ |i| left.concat(right) } }
end
puts *Object.constants.grep(/RUBY/).map { |c| Object.const_get(c) }
0.step(1000, 50) do |n|
puts "Array Size: #{n}"
puts "Push: #{push(n, n)}"
puts "Concat: #{concat(n, n)}"
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment