-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dont run Benchmark test with the others
- Loading branch information
Showing
2 changed files
with
52 additions
and
46 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,69 @@ | ||
$:.unshift File.dirname(__FILE__) + '/../../../lib' | ||
%w( rubygems ambition ambition/adapters/active_record benchmark ).each { |f| require f } | ||
unless defined? Test | ||
$:.unshift File.dirname(__FILE__) + '/../../../lib' | ||
%w( rubygems ambition ambition/adapters/active_record benchmark ).each { |f| require f } | ||
|
||
class User < ActiveRecord::Base | ||
def self.reflections | ||
return @reflections if @reflections | ||
@reflections = {} | ||
@reflections[:ideas] = Reflection.new(:has_many, 'user_id', :ideas, 'ideas') | ||
@reflections[:invites] = Reflection.new(:has_many, 'referrer_id', :invites, 'invites') | ||
@reflections[:profile] = Reflection.new(:has_one, 'user_id', :profile, 'profiles') | ||
@reflections[:account] = Reflection.new(:belongs_to, 'account_id', :account, 'accounts') | ||
@reflections | ||
end | ||
class User < ActiveRecord::Base | ||
def self.reflections | ||
return @reflections if @reflections | ||
@reflections = {} | ||
@reflections[:ideas] = Reflection.new(:has_many, 'user_id', :ideas, 'ideas') | ||
@reflections[:invites] = Reflection.new(:has_many, 'referrer_id', :invites, 'invites') | ||
@reflections[:profile] = Reflection.new(:has_one, 'user_id', :profile, 'profiles') | ||
@reflections[:account] = Reflection.new(:belongs_to, 'account_id', :account, 'accounts') | ||
@reflections | ||
end | ||
|
||
def self.table_name | ||
'users' | ||
def self.table_name | ||
'users' | ||
end | ||
end | ||
end | ||
|
||
class Reflection < Struct.new(:macro, :primary_key_name, :name, :table_name) | ||
end | ||
class Reflection < Struct.new(:macro, :primary_key_name, :name, :table_name) | ||
end | ||
|
||
Times = 10000 | ||
Times = 10000 | ||
|
||
Benchmark.bm(30) do |x| | ||
x.report 'simple select' do | ||
Times.times do | ||
User.select { |u| u.id == 20 }.to_hash | ||
Benchmark.bm(30) do |x| | ||
x.report 'simple select' do | ||
Times.times do | ||
User.select { |u| u.id == 20 }.to_hash | ||
end | ||
end | ||
end | ||
|
||
x.report 'simple select w/ eval' do | ||
Times.times do | ||
User.select { |u| u.created_at == Time.now }.to_hash | ||
x.report 'simple select w/ eval' do | ||
Times.times do | ||
User.select { |u| u.created_at == Time.now }.to_hash | ||
end | ||
end | ||
end | ||
|
||
x.report 'dual select' do | ||
Times.times do | ||
User.select { |u| u.id == 20 && u.age > 20 }.to_hash | ||
x.report 'dual select' do | ||
Times.times do | ||
User.select { |u| u.id == 20 && u.age > 20 }.to_hash | ||
end | ||
end | ||
end | ||
|
||
x.report 'join select' do | ||
Times.times do | ||
User.select { |u| u.id == 20 && u.ideas.name =~ /stuff/ }.to_hash | ||
x.report 'join select' do | ||
Times.times do | ||
User.select { |u| u.id == 20 && u.ideas.name =~ /stuff/ }.to_hash | ||
end | ||
end | ||
end | ||
|
||
x.report 'dual select w/ sort' do | ||
Times.times do | ||
User.select { |u| u.id == 20 && u.age > 20 }.sort_by { |u| u.id }.to_hash | ||
x.report 'dual select w/ sort' do | ||
Times.times do | ||
User.select { |u| u.id == 20 && u.age > 20 }.sort_by { |u| u.id }.to_hash | ||
end | ||
end | ||
end | ||
|
||
x.report 'dual select w/ sort & first' do | ||
Times.times do | ||
User.select { |u| u.id == 20 && u.age > 20 }.sort_by { |u| u.id }.first(20).to_hash | ||
x.report 'dual select w/ sort & first' do | ||
Times.times do | ||
User.select { |u| u.id == 20 && u.age > 20 }.sort_by { |u| u.id }.first(20).to_hash | ||
end | ||
end | ||
end | ||
|
||
x.report "it's complicated" do | ||
Times.times do | ||
User.select { |u| (u.id == 20 && u.age > 20) || u.profile.name == 'Jon' }.sort_by { |u| [u.id, -u.name] }.first(20).to_hash | ||
x.report "it's complicated" do | ||
Times.times do | ||
User.select { |u| (u.id == 20 && u.age > 20) || u.profile.name == 'Jon' }.sort_by { |u| [u.id, -u.name] }.first(20).to_hash | ||
end | ||
end | ||
end | ||
end |
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