Created
September 26, 2011 15:41
-
-
Save sra448/1242529 to your computer and use it in GitHub Desktop.
test performance of method vs method!
This file contains hidden or 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' | |
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