Skip to content

Instantly share code, notes, and snippets.

@sra448
Created September 26, 2011 15:41
Show Gist options
  • Save sra448/1242529 to your computer and use it in GitHub Desktop.
Save sra448/1242529 to your computer and use it in GitHub Desktop.
test performance of method vs method!
require 'benchmark'
def test_extended
test_array = [1, 2, 3, [ 1, 2, 3, 4, [1, 2, 3, 4, 5, 6, 7], 8, [9]], 10]
test_methods = ['collect', 'compact', 'flatten', 'map', 'reject', 'reverse', 'shuffle', 'sort', 'uniq']
Benchmark.bm(10) do |bm|
test_methods.each do |method|
bm.report(method) { 100000.times { test_array.send(method) } }
bm.report(method+ "!") { 100000.times { test_array.send(method + "!") } }
end
end
end
test_extended
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment