Created
April 2, 2015 09:34
-
-
Save liushooter/bd8f058780683d1a4343 to your computer and use it in GitHub Desktop.
Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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