Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions code/enumerable/inject-symbol-plus-vs-sum.rb
Original file line number Diff line number Diff line change
@@ -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