jacobaweiss/reduce_ranges — pull request #3 by Calyhre (2014-07-04 08:29:12+00:00)
Title: Refacto reduce_ranges for performance

A [french blogger](http://lkdjiin.github.io/blog/2014/06/30/exercice-ruby-reduce-ranges/) has launch a small exercise with your algorithm as purpose. The goal was first to made it works, and then, to do the most efficient.

I'm here to propose you my solution with some benchmarks :

```ruby
array = [1, 2, 3, 7, 9, 17, 18, 19, 20]

Benchmark.bmbm do |x|
x.report('calyhre') { 100_000.times { array.reduce_ranges } }
x.report('original') { 100_000.times { array.reduce_ranges } }
end

# Rehearsal --------------------------------------------
# calyhre 0.440000 0.000000 0.440000 ( 0.437160)
# original 0.510000 0.000000 0.510000 ( 0.511847)
# ----------------------------------- total: 0.950000sec
#
# user system total real
# calyhre 0.440000 0.000000 0.440000 ( 0.435045)
# original 0.490000 0.010000 0.500000 ( 0.485511)

```