Hi all,
Can anyone explain where is the bottlenecks in this examples: DM shows
slow results in comparing with AR
AR:
%w( rubygems spec active_record benchmark).each{|lib| require lib}
class StageItem < ActiveRecord::Base
validates_numericality_of :input, :output, :greater_than_or_equal_to
=> 0
validates_presence_of :user_id, :item_id, :x_coord, :y_coord
end
class SoilItem < StageItem
end
ActiveRecord::Base.establish_connection :adapter => "postgresql",
:database => "contry_development_3", :username =>
"postgres", :password => "123", :host => "127.0.0.1", :port => 5432
describe StageItem do
it 'should create stageitem' do
SoilItem.connection.transaction do
n = 500
Benchmark.bmbm do |x|
x.report {n.times { SoilItem.create(:user_id => 1, :item_id =>
1, :x_coord => 2, :y_coord => 4).should be_valid } }
end
end
end
end
Simple example gives us following results:
Finished in 3.736249 seconds
DM:
%w( rubygems spec dm-core dm-migrations dm-validations benchmark dm-
transactions dm-timestamps).each{|lib| require lib}
class StageItem
include DataMapper::Resource
property :id, Serial
property :user_id, Integer, :required => true
property :item_id, Integer, :required => true
property :x_coord, Integer, :required => true
property :y_coord, Integer, :required => true
property :type, Discriminator
end
class SoilItem < StageItem
end
DataMapper.setup(:default, :adapter=>"postgres", :user=>"postgres",
:password=>"123", :host
=> "localhost", :path=>"/contry_development_3")
describe StageItem do
it 'should create stageitem' do
StageItem.transaction do
n = 500
Benchmark.bmbm do |x|
x.report {n.times { SoilItem.create(:user_id => 1, :item_id =>
1, :x_coord => 2, :y_coord => 4).should be_valid } }
end
end
end
end
Simple example gives us following results:
Finished in 2.646424 seconds
Not bad.
I've added several properties and timestamps
property :input, Integer, :required => true, :default => 0
property :output, Integer, :required => true, :default => 0
property :extra_input, String, :required => false
property :extra_output, String, :required => false
property :extra1, Integer
timestamps :at
Results now is following:
Finished in 5.370599 seconds
Why the time is increased so much? How should I improve it?
Great thanks, Roman
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.