Created
June 10, 2017 10:14
-
-
Save skatkov/40702ceb60c22c54d19928b6d92d04da to your computer and use it in GitHub Desktop.
map bencmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
ruby '2.4' | |
gem 'benchmark-ips' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
x.report('map_block') { (1..100000).map { |i| i.to_s } } | |
x.report('map_&') { (1..100000).map(&:to_s) } | |
x.compare! | |
end | |
=begin | |
MRI 2.4 | |
Warming up -------------------------------------- | |
map_block 5.000 i/100ms | |
map_& 4.000 i/100ms | |
Calculating ------------------------------------- | |
map_block 46.775 (± 4.3%) i/s - 235.000 in 5.036210s | |
map_& 64.124 (± 4.7%) i/s - 324.000 in 5.062029s | |
Comparison: | |
map_&: 64.1 i/s | |
map_block: 46.8 i/s - 1.37x slower | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment