Skip to content

Commit

Permalink
performance test to see how well associations and creates perform on …
Browse files Browse the repository at this point in the history
…large data sets
  • Loading branch information
Bob Remeika committed Nov 1, 2010
1 parent 0959bda commit 057b670
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions performance/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rubygems'
require 'tractor'
require 'faker'

Tractor.connectdb
Tractor.flushdb

class Person < Tractor::Model::Base
attribute :id
attribute :first_name, :index => true
attribute :last_name, :index => true
attribute :awesome, :type => :boolean, :index => true
attribute :company_id, :index => true
end

class Company < Tractor::Model::Base
association :people, Person

attribute :id
attribute :name
end


100.times do |i|
Company.create(:id => i+1, :name => Faker::Company.name)
end

10000.times do |i|
Person.create(
:id => i+1,
:first_name => Faker::Name.first_name,
:last_name => Faker::Name.last_name,
:awesome => rand(2)==0,
:company_id => rand(Company.count)+1)
end

Company.all.each do |company|
t1 = Time.now
employees = company.people.all
t2 = Time.now
puts "Company #{company.id} has #{employees.size} employees and it took #{t2-t1} seconds to retrieve them all"
end
2 changes: 1 addition & 1 deletion tractor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Shane Wolf"]
s.date = %q{2010-10-29}
s.date = %q{2010-11-01}
s.description = %q{Very simple object mappings for ruby objects}
s.email = %q{shanewolf@gmail.com}
s.extra_rdoc_files = [
Expand Down

0 comments on commit 057b670

Please sign in to comment.