aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/examples
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-12-15 20:26:33 +0100
committerJosé Valim <jose.valim@gmail.com>2011-12-15 20:47:26 +0100
commit1e8b75181306ada87b1a4b05d1551348dd916f91 (patch)
tree6a2594022a82a3fabef5970ff112729d949ca04b /activerecord/examples
parent22bd21dc0fc0535f1de93d22569e8769c2e43949 (diff)
downloadrails-1e8b75181306ada87b1a4b05d1551348dd916f91.tar.gz
rails-1e8b75181306ada87b1a4b05d1551348dd916f91.tar.bz2
rails-1e8b75181306ada87b1a4b05d1551348dd916f91.zip
Make with_scope public so we stop using send :bomb:
Diffstat (limited to 'activerecord/examples')
-rw-r--r--activerecord/examples/performance.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/examples/performance.rb b/activerecord/examples/performance.rb
index d29af85278..31f3e02bb8 100644
--- a/activerecord/examples/performance.rb
+++ b/activerecord/examples/performance.rb
@@ -29,6 +29,14 @@ class Exhibit < ActiveRecord::Base
def look; attributes end
def feel; look; user.name end
+ def self.with_name
+ where("name IS NOT NULL")
+ end
+
+ def self.with_notes
+ where("notes IS NOT NULL")
+ end
+
def self.look(exhibits) exhibits.each { |e| e.look } end
def self.feel(exhibits) exhibits.each { |e| e.feel } end
end
@@ -109,6 +117,10 @@ Benchmark.bm(46) do |x|
TIMES.times { Exhibit.first.look }
end
+ x.report 'Model.named_scope' do
+ TIMES.times { Exhibit.limit(10).with_name.with_notes }
+ end
+
x.report("Model.all limit(100) (x#{(TIMES / 10).ceil})") do
(TIMES / 10).ceil.times { Exhibit.look Exhibit.limit(100) }
end