aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorGuo Xiang Tan <tgx_world@hotmail.com>2015-09-07 11:56:16 +0800
committerGuo Xiang Tan <tgx_world@hotmail.com>2015-09-07 12:45:42 +0800
commit52b2ab9e01dd6d0062c1af46abd2ef9fac2dd584 (patch)
tree3fe9c2f48afa7a45ab6f426fe5e2f05ec31b7747 /activemodel
parent47e06c988e8377d04a6a6e28e798b06187326d87 (diff)
downloadrails-52b2ab9e01dd6d0062c1af46abd2ef9fac2dd584.tar.gz
rails-52b2ab9e01dd6d0062c1af46abd2ef9fac2dd584.tar.bz2
rails-52b2ab9e01dd6d0062c1af46abd2ef9fac2dd584.zip
Cache check if `default_scope` has been overridden.
Benchmark Script: ``` begin require 'bundler/inline' rescue LoadError => e $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' raise e end gemfile(true) do source 'https://rubygems.org' # gem 'rails', github: 'rails/rails', ref: 'f1f0a3f8d99aef8aacfa81ceac3880dcac03ca06' gem 'rails', path: '~/rails' gem 'arel', github: 'rails/arel', branch: 'master' gem 'rack', github: 'rack/rack', branch: 'master' gem 'sass' gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master' gem 'sprockets', github: 'rails/sprockets', branch: 'master' gem 'pg' gem 'benchmark-ips' end require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection('postgres://postgres@localhost:5432/rubybench') ActiveRecord::Migration.verbose = false ActiveRecord::Schema.define do create_table :users, force: true do |t| t.string :name, :email t.timestamps null: false end end class User < ActiveRecord::Base; end attributes = { name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", email: "foobar@email.com", } 1000.times { User.create!(attributes) } Benchmark.ips(5, 3) do |x| x.report('where with hash') { User.where(name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") } x.report('where with string') { User.where("users.name = ?", "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") } x.compare! end key = if RUBY_VERSION < '2.2' :total_allocated_object else :total_allocated_objects end before = GC.stat[key] User.where(name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") after = GC.stat[key] puts "Total Allocated Object: #{after - before}" ``` Stackprof output truncated. ``` TOTAL (pct) SAMPLES (pct) FRAME 52 (10.6%) 10 (2.0%) ActiveRecord::Scoping::Default::ClassMethods#build_default_scope ``` Before: ``` Calculating ------------------------------------- where with hash 2.789k i/100ms where with string 4.407k i/100ms ------------------------------------------------- where with hash 29.170k (± 1.9%) i/s - 147.817k where with string 46.954k (± 2.7%) i/s - 237.978k Comparison: where with string: 46954.3 i/s where with hash: 29169.9 i/s - 1.61x slower Total Allocated Object: 85 Calculating ------------------------------------- all 16.773k i/100ms ------------------------------------------------- all 186.102k (± 3.6%) i/s - 939.288k ``` After: ``` Calculating ------------------------------------- where with hash 3.014k i/100ms where with string 4.623k i/100ms ------------------------------------------------- where with hash 31.524k (± 1.3%) i/s - 159.742k where with string 49.948k (± 2.3%) i/s - 249.642k Comparison: where with string: 49948.3 i/s where with hash: 31524.3 i/s - 1.58x slower Total Allocated Object: 84 Calculating ------------------------------------- all 20.139k i/100ms ------------------------------------------------- all 227.860k (± 2.5%) i/s - 1.148M ```
Diffstat (limited to 'activemodel')
0 files changed, 0 insertions, 0 deletions