Skip to content

Instantly share code, notes, and snippets.

@sergey-alekseev
Created March 12, 2015 01:04
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 sergey-alekseev/f62c7b08ba68ee6299ea to your computer and use it in GitHub Desktop.
Save sergey-alekseev/f62c7b08ba68ee6299ea to your computer and use it in GitHub Desktop.
exists? vs. any?
Benchmark.ips do |x|
x.report('exists?') { user.printers.exists? }
x.report('any?') { user.printers.any? }
x.compare!
end
Comparison:
any?: 615.6 i/s
exists?: 601.8 i/s - 1.02x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment