Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Last active September 6, 2019 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahemoff/7232648e1ccb9d23e0f4670913400bd8 to your computer and use it in GitHub Desktop.
Save mahemoff/7232648e1ccb9d23e0f4670913400bd8 to your computer and use it in GitHub Desktop.
in versus include
#!/usr/bin/env ruby
require 'benchmark'
require 'active_support/all'
puts 'in', Benchmark.measure { 90000.in?(1..99000)}
puts 'include', Benchmark.measure { (1..99000).include? 90000 }
in
0.000007 0.000000 0.000007 ( 0.000004)
include
0.000004 0.000000 0.000004 ( 0.000023)
@mahemoff
Copy link
Author

mahemoff commented Sep 6, 2019

with 1000.times inside the measure, very close

in
  0.000158   0.000018   0.000176 (  0.000173)
include
  0.000181   0.000021   0.000202 (  0.000201)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment