Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

dont run Benchmark test with the others

  • Loading branch information...
commit b90af1ae73dfb7366fde0a443084aa438d355332 1 parent 82636d6
@defunkt authored
View
94 adapters/ambitious_activerecord/test/benchmark.rb
@@ -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
View
4 adapters/ambitious_activerecord/test/helper.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.