Skip to content

Commit

Permalink
dont run Benchmark test with the others
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Feb 16, 2008
1 parent 82636d6 commit b90af1a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 46 deletions.
94 changes: 48 additions & 46 deletions adapters/ambitious_activerecord/test/benchmark.rb
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
4 changes: 4 additions & 0 deletions adapters/ambitious_activerecord/test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Reflection < Struct.new(:macro, :primary_key_name, :name, :table_name)
module ActiveRecord
module ConnectionAdapters
class MysqlAdapter
def initialize(*args)
super
end

def connect(*args)
true
end
Expand Down

0 comments on commit b90af1a

Please sign in to comment.