0
require File.join(File.dirname(__FILE__), '..', 'lib', 'dm-core')
0
+# gem install somebee-rbench -s http://gems.github.com
0
+# OR git clone git://github.com/somebee/rbench.git; rake install
0
+# gem 'somebee-rbench', '>=0.2.0'
0
@@ -34,6 +39,7 @@ log_dir.mkdir unless log_dir.directory?
0
DataMapper::Logger.new(log_dir / 'dm.log', :debug)
0
adapter = DataMapper.setup(:default, "mysql://root@localhost/data_mapper_1?socket=#{socket_file}")
0
+sqlfile = File.join(File.dirname(__FILE__),'..','tmp','perf.sql')
0
ActiveRecord::Base.logger = Logger.new(log_dir / 'ar.log')
0
ActiveRecord::Base.logger.level = 0
0
@@ -52,7 +58,7 @@ class Exhibit
0
property :id, Integer, :serial => true
0
property :zoo_id, Integer
0
- property :notes,
DM::Text, :lazy => true
0
+ property :notes,
Text, :lazy => true
0
property :created_on, Date
0
# property :updated_at, DateTime
0
@@ -66,221 +72,159 @@ touch_attributes = lambda do |exhibits|
0
-# pre-compute the insert statements and fake data compilation,
0
-# so the benchmarks below show the actual runtime for the execute
0
-# method, minus the setup steps
0
-# 'INSERT INTO `exhibits` (`name`, `zoo_id`, `notes`, `created_on`, `updated_at`) VALUES (?, ?, ?, ?, ?)'
0
- 'INSERT INTO `exhibits` (`name`, `zoo_id`, `notes`, `created_on`) VALUES (?, ?, ?, ?)',
0
- Faker::Lorem.paragraphs.join($/),
0
-Benchmark.bmbm(60) do |x|
0
- x.report('DO.execute insert x10,000') do
0
- 10_000.times { |i| adapter.execute(*exhibits.at(i)) }
0
- x.report('AR.id x10,000') do
0
- ActiveRecord::Base::uncached do
0
- 10_000.times { touch_attributes[ARExhibit.find(1)] }
0
- x.report('DM.id x10,000') do
0
- 10_000.times { touch_attributes[Exhibit.get(1)] }
0
- x.report('AR.id x10,000 (cached)') do
0
- ActiveRecord::Base::cache do
0
- 10_000.times { touch_attributes[ARExhibit.find(1)] }
0
- x.report('DM.id x10,000 (cached)') do
0
- repository(:default) do
0
- 10_000.times { touch_attributes[Exhibit.get(1)] }
0
- x.report('AR.first x10,000') do
0
- 10_000.times { touch_attributes[ARExhibit.find(:first)] }
0
- x.report('DM.first x10,000') do
0
- 10_000.times { touch_attributes[Exhibit.first] }
0
- x.report('AR.all limit(100) x1,000') do
0
- ActiveRecord::Base::uncached do
0
- 1000.times { touch_attributes[ARExhibit.find(:all, :limit => 100)] }
0
- x.report('DM.all limit(100) x1,000') do
0
- 1000.times { touch_attributes[Exhibit.all(:limit => 100)] }
0
- x.report('AR.all limit(100) x1,000 (cached)') do
0
- ActiveRecord::Base::cache do
0
- 1000.times { touch_attributes[ARExhibit.find(:all, :limit => 100)] }
0
- x.report('DM.all limit(100) x1,000 (cached)') do
0
- repository(:default) do
0
- 1000.times { touch_attributes[Exhibit.all(:limit => 100)] }
0
- x.report('AR.all limit(10,000) x10') do
0
- ActiveRecord::Base::uncached do
0
- 10.times { touch_attributes[ARExhibit.find(:all, :limit => 10_000)] }
0
- x.report('DM.all limit(10,000) x10') do
0
- 10.times { touch_attributes[Exhibit.all(:limit => 10_000)] }
0
- x.report('AR.all limit(10,000) x10 (cached)') do
0
- ActiveRecord::Base::cache do
0
- 10.times { touch_attributes[ARExhibit.find(:all, :limit => 10_000)] }
0
+c = configuration_options
0
+if File.exists?(sqlfile) && configuration_options[:adapter] == 'mysql'
0
+ puts "Found data-file. Importing from #{sqlfile}"
0
+ `mysql -u #{c[:username]} #{"-p#{c[:password]}" unless c[:password].blank?} #{c[:database]} < #{sqlfile}`
0
+ # pre-compute the insert statements and fake data compilation,
0
+ # so the benchmarks below show the actual runtime for the execute
0
+ # method, minus the setup steps
0
+ 'INSERT INTO `exhibits` (`name`, `zoo_id`, `notes`, `created_on`) VALUES (?, ?, ?, ?)',
0
+ Faker::Lorem.paragraphs.join($/),
0
+ 10_000.times { |i| adapter.execute(*exhibits.at(i)) }
0
+ if configuration_options[:adapter] == 'mysql'
0
+ until answer && answer[/^$|y|yes|n|no/]
0
+ print("Would you like to dump data into tmp/perf.sql (for faster setup)? [Yn]");
0
- x.report('DM.all limit(10,000) x10 (cached)') do
0
- repository(:default) do
0
- 10.times { touch_attributes[Exhibit.all(:limit => 10_000)] }
0
+ File.makedirs(File.dirname(sqlfile))
0
+ `mysqldump -u #{c[:username]} #{"-p#{c[:password]}" unless c[:password].blank?} #{c[:database]} exhibits > #{sqlfile}`
0
- # Static, just so AR and DM are on equal footing.
0
+TIMES = ENV['x'] ? ENV['x'].to_i : 10_000
0
+puts "You can specify how many times you want to run the benchmarks with rake:perf x=(number)"
0
+puts "Some tasks will be run 10 and 1000 times less than (number)"
0
+puts "Benchmarks will now run #{TIMES} times"
0
+ column :dm, :title => "DM 0.9.2"
0
+ column :ar, :title => "AR 2.1"
0
+ column :diff, :compare => [:dm,:ar]
0
+ report "#get specific (not cached)" do
0
+ dm { touch_attributes[Exhibit.get(1)] }
0
+ ActiveRecord::Base::uncached { ar { touch_attributes[ARExhibit.find(1)] } }
0
+ report "#get specific (cached)" do
0
+ Exhibit.repository(:default) { dm { touch_attributes[Exhibit.get(1)] } }
0
+ ActiveRecord::Base::cache { ar { touch_attributes[ARExhibit.find(1)] } }
0
+ report "#get first" do
0
+ dm { touch_attributes[Exhibit.first] }
0
+ ar { touch_attributes[ARExhibit.first] }
0
+ report "#all limit(100) (not cached)", TIMES / 10 do
0
+ dm { touch_attributes[Exhibit.all(:limit => 100)] }
0
+ ar { touch_attributes[ARExhibit.find(:all, :limit => 100)] }
0
+ report "#all limit(100) (cached)", TIMES / 10 do
0
+ Exhibit.repository(:default) { dm { touch_attributes[Exhibit.all(:limit => 100)] } }
0
+ ActiveRecord::Base::cache { ar { touch_attributes[ARExhibit.find(:all, :limit => 100)] } }
0
+ report "#all limit(10,000) (not cached)", TIMES / 1000 do
0
+ dm { touch_attributes[Exhibit.all(:limit => 10_000)] }
0
+ ar { touch_attributes[ARExhibit.find(:all, :limit => 10_000)] }
0
+ report "#all limit(10,000) (cached)", TIMES / 1000 do
0
+ Exhibit.repository(:default) { dm { touch_attributes[Exhibit.all(:limit => 10_000)] } }
0
+ ActiveRecord::Base::cache { ar { touch_attributes[ARExhibit.find(:all, :limit => 10_000)] } }
0
:name => Faker::Company.name,
0
:zoo_id => rand(10).ceil,
0
:notes => Faker::Lorem.paragraphs.join($/),
0
- :created_on => Date.today,
0
-# :updated_at => Time.now,
0
+ :created_on => Date.today
0
- x.report('AR.create x10,000') do
0
- 10_000.times { ARExhibit.create(create_exhibit) }
0
- x.report('DM.create x10,000') do
0
- 10_000.times { Exhibit.create(create_exhibit) }
0
+ dm { Exhibit.create(create_exhibit) }
0
+ ar { ARExhibit.create(create_exhibit) }
0
- x.report('AR#update x10,000') do
0
- 10_000.times { e = ARExhibit.find(1); e.name = 'bob'; e.save }
0
+ dm { e = Exhibit.get(1); e.name = 'bob'; e.save }
0
+ ar { e = ARExhibit.find(1); e.name = 'bob'; e.save }
0
- x.report('DM#update x10,000') do
0
- 10_000.times { e = Exhibit.get(1); e.name = 'bob'; e.save }
0
- x.report('AR#destroy x10,000') do
0
- # destroy records 1 to 10,000
0
- (1..10_000).each { |id| ARExhibit.find(id).destroy }
0
- x.report('DM#destroy x10,000') do
0
- # destroy records 10,001 to 20,000
0
- (10_001..20_000).each { |id| Exhibit.get(id).destroy }
0
+ dm { Exhibit.first.destroy }
0
+ ar { ARExhibit.first.destroy }
0
-# connection = adapter.create_connection
0
-# command = connection.create_command("DROP TABLE exhibits")
0
-# command.execute_non_query rescue nil
0
+connection = adapter.send(:create_connection)
0
+command = connection.create_command("DROP TABLE exhibits")
0
+command.execute_non_query rescue nil
0
-On an iMac Core2Duo 2.16GHz:
0
-I don't think AR is actually caching.
0
-~/src/dm-core > script/performance.rb
0
-Text should not be declared inline.
0
-Rehearsal -----------------------------------------------------------------------------------------------
0
-ActiveRecord:id x10_000 3.530000 0.320000 3.850000 ( 4.939399)
0
-ActiveRecord:id(cached) x10_000 3.540000 0.320000 3.860000 ( 4.797453)
0
-DataMapper:id x10_000 3.190000 0.280000 3.470000 ( 4.604910)
0
-DataMapper:id(cached) x10_000 0.090000 0.000000 0.090000 ( 0.095606)
0
-ActiveRecord:all limit(100) x1000 11.880000 0.060000 11.940000 ( 12.494454)
0
-ActiveRecord:all limit(100) (cached) x1000 11.860000 0.060000 11.920000 ( 12.521918)
0
-DataMapper:all limit(100) x1000 5.020000 0.040000 5.060000 ( 5.578594)
0
-DataMapper:all limit(100) (cached) x1000 3.040000 0.040000 3.080000 ( 3.581179)
0
-ActiveRecord:all limit(10,000) x10 12.040000 0.050000 12.090000 ( 12.243110)
0
-ActiveRecord:all limit(10,000) (cached) x10 12.140000 0.040000 12.180000 ( 12.339861)
0
-DataMapper:all limit(10,000) x10 5.740000 0.040000 5.780000 ( 5.788256)
0
-DataMapper:all limit(10,000) (cached) x10 3.850000 0.020000 3.870000 ( 3.874642)
0
-------------------------------------------------------------------------------------- total: 77.190000sec
0
- user system total real
0
-ActiveRecord:id x10_000 3.480000 0.320000 3.800000 ( 4.701110)
0
-ActiveRecord:id(cached) x10_000 3.480000 0.310000 3.790000 ( 4.701436)
0
-DataMapper:id x10_000 3.170000 0.270000 3.440000 ( 4.375630)
0
-DataMapper:id(cached) x10_000 0.100000 0.000000 0.100000 ( 0.097554)
0
-ActiveRecord:all limit(100) x1000 11.410000 0.060000 11.470000 ( 11.993949)
0
-ActiveRecord:all limit(100) (cached) x1000 11.410000 0.050000 11.460000 ( 11.998727)
0
-DataMapper:all limit(100) x1000 5.060000 0.040000 5.100000 ( 5.608384)
0
-DataMapper:all limit(100) (cached) x1000 3.020000 0.040000 3.060000 ( 3.554985)
0
-ActiveRecord:all limit(10,000) x10 12.170000 0.040000 12.210000 ( 12.370468)
0
-ActiveRecord:all limit(10,000) (cached) x10 12.180000 0.040000 12.220000 ( 12.371510)
0
-DataMapper:all limit(10,000) x10 5.450000 0.020000 5.470000 ( 5.480993)
0
-DataMapper:all limit(10,000) (cached) x10 3.130000 0.020000 3.150000 ( 3.160792)
0
-On a MacBook Air Core2Duo 1.6GHz (many performance optimizations since the run above)
0
-~/src/dm-core > script/performance.rb
0
-Rehearsal -----------------------------------------------------------------------------------------------
0
-AR.id x10,000 11.290000 0.420000 11.710000 ( 14.845046)
0
-DM.id x10,000 5.010000 0.480000 5.490000 ( 8.738212)
0
-AR.id x10,000 (cached) 12.300000 0.520000 12.820000 ( 16.585108)
0
-DM.id x10,000 (cached) 0.450000 0.000000 0.450000 ( 0.474010)
0
-AR.all limit(100) x1,000 3.340000 0.080000 3.420000 ( 4.554041)
0
-DM.all limit(100) x1,000 1.420000 0.050000 1.470000 ( 1.743724)
0
-AR.all limit(100) x1,000 (cached) 3.450000 0.070000 3.520000 ( 3.937980)
0
-DM.all limit(100) x1,000 (cached) 1.070000 0.050000 1.120000 ( 1.390889)
0
-AR.all limit(10,000) x10 0.020000 0.000000 0.020000 ( 0.031253)
0
-DM.all limit(10,000) x10 0.020000 0.000000 0.020000 ( 0.017896)
0
-AR.all limit(10,000) x10 (cached) 0.030000 0.000000 0.030000 ( 0.032688)
0
-DM.all limit(10,000) x10 (cached) 0.010000 0.000000 0.010000 ( 0.013167)
0
-AR.create x10,000 21.390000 1.290000 22.680000 ( 28.519556)
0
-DM.create x10,000 20.090000 0.630000 20.720000 ( 28.822219)
0
-AR.update x10,000 25.450000 1.660000 27.110000 ( 33.040779)
0
-DM.update x10,000 6.550000 0.780000 7.330000 ( 10.467941)
0
------------------------------------------------------------------------------------- total: 117.920000sec
0
+ | DM 0.9.2 | AR 2.1 | DIFF |
0
+--------------------------------------------------------------------------------
0
+get specific (not cached) x10000 | 8.949 | 3.108 | 2.88x |
0
+get specific (cached) x10000 | 0.223 | 3.090 | 0.07x |
0
+get first x10000 | 6.987 | 2.756 | 2.54x |
0
+#all limit(100) (not cached) x1000 | 6.625 | 7.734 | 0.86x |
0
+#all limit(100) (cached) x1000 | 4.828 | 7.686 | 0.63x |
0
+#all limit(10,000) (not cached) x10 | 6.252 | 9.145 | 0.68x |
0
+#all limit(10,000) (cached) x10 | 5.001 | 9.368 | 0.53x |
0
+#create x10000 | 38.884 | 21.757 | 1.79x |
0
+#update x10000 | 9.102 | 6.790 | 1.34x |
0
+#destroy x10000 | 30.391 | 21.502 | 1.41x |
0
+================================================================================
0
+Total | 117.242 | 92.936 | 1.26x |
0
+## PROBLEMS WITH THE RECENT DAYS COMMITS !!! ##
0
+ | DM 0.9.2 | AR 2.1 | DIFF |
0
+--------------------------------------------------------------------------------
0
+#get specific (not cached) x1000 | 12.490 | 0.309 | 40.43x |
0
+#get specific (cached) x1000 | 3.980 | 0.305 | 13.03x |
0
+#get first x1000 | 10.087 | 0.277 | 36.39x |
0
+#all limit(100) (not cached) x100 | 59.252 | 0.780 | 75.92x |
0
+#all limit(100) (cached) x100 | 41.236 | 0.774 | 53.24x |
0
+#all limit(10,000) (not cached) x1 | 71.123 | 0.826 | 86.12x |
0
+#all limit(10,000) (cached) x1 | 72.477 | 0.835 | 86.79x |
0
+#create x1000 | 24.836 | 2.219 | 11.19x |
0
+#update x1000 | 9.866 | 0.645 | 15.31x |
0
+#destroy x1000 | 12.892 | 1.512 | 8.52x |
0
+================================================================================
0
+Total 0 | 318.237 | 8.483 | 42.69x |
0
- user system total real
0
-AR.id x10,000 11.320000 0.420000 11.740000 ( 13.907577)
0
-DM.id x10,000 4.510000 0.410000 4.920000 ( 6.611278)
0
-AR.id x10,000 (cached) 11.680000 0.440000 12.120000 ( 14.792082)
0
-DM.id x10,000 (cached) 0.380000 0.010000 0.390000 ( 0.384611)
0
-AR.all limit(100) x1,000 25.010000 0.200000 25.210000 ( 25.954076)
0
-DM.all limit(100) x1,000 10.370000 0.090000 10.460000 ( 11.558341)
0
-AR.all limit(100) x1,000 (cached) 28.390000 0.350000 28.740000 ( 30.870503)
0
-DM.all limit(100) x1,000 (cached) 7.760000 0.110000 7.870000 ( 9.211700)
0
-AR.all limit(10,000) x10 27.850000 0.240000 28.090000 ( 28.510220)
0
-DM.all limit(10,000) x10 10.970000 0.040000 11.010000 ( 11.042093)
0
-AR.all limit(10,000) x10 (cached) 29.230000 0.170000 29.400000 ( 29.816547)
0
-DM.all limit(10,000) x10 (cached) 7.470000 0.030000 7.500000 ( 7.520561)
0
-AR.create x10,000 21.700000 1.400000 23.100000 ( 27.188424)
0
-DM.create x10,000 24.380000 0.550000 24.930000 ( 29.439910)
0
-AR.update x10,000 30.670000 1.910000 32.580000 ( 39.227956)
0
-DM.update x10,000 8.290000 0.950000 9.240000 ( 12.912708)
Comments
No one has commented yet.