Skip to content

Instantly share code, notes, and snippets.

@liushooter
Created April 2, 2015 09:34
Show Gist options
  • Save liushooter/bd8f058780683d1a4343 to your computer and use it in GitHub Desktop.
Save liushooter/bd8f058780683d1a4343 to your computer and use it in GitHub Desktop.
Benchmark
require 'benchmark'
# rails runner auto.rb
class AutoTest
n = 1000
Benchmark.bm do |x|
x.report do
n.times{ AutoSubmodel.except(:cities).all.last }
end
x.report do
AutoSubmodel.all.last
end
end
end
module Mongoid
module BaseModel
extend ActiveSupport::Concern
included do
scope :recent, -> { desc(:create_at) }
end
module ClassMethods
# https://github.com/rails/rails/blob/f37ad331089f64ab0386e8ac94b6626b45c38a1e/activesupport/lib/active_support/concern.rb
def except(*attr)
only(attribute_names.map(&:to_sym) - attr)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment