diff --git a/.travis.yml b/.travis.yml index d26fd4b..a9445a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ cache: bundler bundler_args: --retry=3 --jobs=3 language: ruby rvm: + - 2.4.1 - 2.3.0 - 2.1.8 - 2.2.4 diff --git a/code/enumerable/inject-symbol-plus-vs-sum.rb b/code/enumerable/inject-symbol-plus-vs-sum.rb new file mode 100644 index 0000000..780f093 --- /dev/null +++ b/code/enumerable/inject-symbol-plus-vs-sum.rb @@ -0,0 +1,19 @@ +require "rubygems" +require "benchmark/ips" + +ARRAY = (1..1000).to_a + +def fast + ARRAY.sum +end + +def slow + ARRAY.inject(:+) +end + +Benchmark.ips do |x| + x.report('sum') { fast } + x.report('inject symbol plus') { slow } + + x.compare! +end