Skip to content

Instantly share code, notes, and snippets.

@sergey-alekseev
Created March 12, 2015 01:04
Show Gist options
  • Select an option

  • Save sergey-alekseev/f62c7b08ba68ee6299ea to your computer and use it in GitHub Desktop.

Select an option

Save sergey-alekseev/f62c7b08ba68ee6299ea to your computer and use it in GitHub Desktop.

Revisions

  1. sergey-alekseev created this gist Mar 12, 2015.
    9 changes: 9 additions & 0 deletions exists-vs-any-comparison.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    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