Last active
December 17, 2015 13:29
-
-
Save Erol/5617833 to your computer and use it in GitHub Desktop.
Benchmark: Tap vs Non-Tap
This file contains 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' | |
def tap_method | |
result = rand.tap {} | |
end | |
def non_tap_method | |
result = rand | |
result | |
end | |
n = 100_000 | |
Benchmark.bm(10) do |bm| | |
bm.report('tap') { n.times { tap_method } } | |
bm.report('non-tap') { n.times { no_tap_method } } | |
end |
This file contains 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
user system total real | |
tap 0.030000 0.000000 0.030000 ( 0.029819) | |
non-tap 0.020000 0.000000 0.020000 ( 0.018391) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment