Created
July 4, 2017 01:12
-
-
Save toshimaru/198a714f48517fa630f3476757d67a57 to your computer and use it in GitHub Desktop.
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| | |
ary = [] | |
x.report(:a) { | |
10_000.times do |num| | |
ary << "#{num} #{num * 2} #{num * 3}" | |
end | |
} | |
x.report(:b){ | |
calc_num = -> (n) { "#{n} #{n * 2} #{n * 3}" } | |
10_000.times do |num| | |
ary << calc_num.call(num) | |
end | |
} | |
x.compare! | |
end |
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
Warming up -------------------------------------- | |
a 13.000 i/100ms | |
b 10.000 i/100ms | |
Calculating ------------------------------------- | |
a 109.073 (±22.9%) i/s - 468.000 in 5.057635s | |
b 81.887 (±41.5%) i/s - 300.000 in 5.174320s | |
Comparison: | |
a: 109.1 i/s | |
b: 81.9 i/s - same-ish: difference falls within error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment