1 # Copied with permission from Antoni Cangiano's blog:
2 # http://antoniocangiano.com/2008/03/25/inject-each-and-times-methods-much-slower-in-ruby-19
8 (1..self).inject(0) { |sum, i| sum + i }
13 (1..self).each { |i| sum += i }
19 (self+1).times { |i| sum += i}
35 puts "=== 10^#{p} ==="
37 x.report("inject: ") { n.sum_with_inject }
38 x.report("each: ") { n.sum_with_each }
39 x.report("times: ") { n.sum_with_times }
40 x.report("while: ") { n.sum_with_while }