From b5f02dd5caedf3ddef8b1027f7e2841a1a214e37 Mon Sep 17 00:00:00 2001 From: Joseph Haig Date: Sat, 23 Dec 2017 23:48:11 +0000 Subject: [PATCH 1/2] Add test for `ARRAY.inject(:+)` vs `ARRAY.sum` --- code/enumerable/inject-symbol-plus-vs-sum.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 code/enumerable/inject-symbol-plus-vs-sum.rb 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 From 0941994c365611d442030e837e19e20d57533841 Mon Sep 17 00:00:00 2001 From: Joseph Haig Date: Sat, 23 Dec 2017 23:55:15 +0000 Subject: [PATCH 2/2] Test for Ruby 2.4.1 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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