Skip to content

Instantly share code, notes, and snippets.

@akshaymohite
Last active May 12, 2017 08:32
Show Gist options
  • Save akshaymohite/92cf1cdab1ba42b2236261ec6fe816ec to your computer and use it in GitHub Desktop.
Save akshaymohite/92cf1cdab1ba42b2236261ec6fe816ec to your computer and use it in GitHub Desktop.
Benchmark between member include in Ruby
Benchmark.bmbm do |x|
x.report { 100000000.times{ 14.between?(10,20)}}
x.report{ 100000000.times{(10..20).member?(14)}}
x.report{ 100000000.times{(10..20).include?(14)}}
end
# result
# Rehearsal ------------------------------------
# 14.030000 0.010000 14.040000 ( 14.028154)
# 14.170000 0.010000 14.180000 ( 14.171821)
# 14.180000 0.010000 14.190000 ( 14.172843)
# -------------------------- total: 42.410000sec
# user system total real
# 14.100000 0.010000 14.110000 ( 14.097643)
# 14.440000 0.020000 14.460000 ( 14.442529)
# 14.390000 0.010000 14.400000 ( 14.385773)
# => [ 14.100000 0.010000 14.110000 ( 14.097643),
# 14.440000 0.020000 14.460000 ( 14.442529),
# 14.390000 0.010000 14.400000 ( 14.385773)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment