Skip to content

Instantly share code, notes, and snippets.

@tal
Created April 9, 2010 18:21
Show Gist options
  • Select an option

  • Save tal/361430 to your computer and use it in GitHub Desktop.

Select an option

Save tal/361430 to your computer and use it in GitHub Desktop.
require 'benchmark'
Benchmark.bmbm do |x|
x.report 'each_with_index' do
i = []
[*1..1000].each_with_index do |item, index|
i << item*index
end
end
x.report 'enum_for collect with_index' do
[*1..1000].enum_for(:collect).with_index do |item,index|
item*index
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment