Permalink
Browse files

update ActiveRecord benchmark to include lazy date/time casting

  • Loading branch information...
1 parent 726b773 commit 7325884d5f5b3a052ccad3176542151aee0e7cd9 @brianmario committed May 19, 2011
Showing with 83 additions and 3 deletions.
  1. +83 −3 benchmark/active_record.rb
View
@@ -22,13 +22,83 @@ class Mysql2Model < ActiveRecord::Base
set_table_name :mysql2_test
end
+class Mysql2Model2 < ActiveRecord::Base
+ set_table_name :mysql2_test
+end
+
class MysqlModel < ActiveRecord::Base
set_table_name :mysql2_test
end
+Mysql2Model.establish_connection(mysql2_opts)
+
+Mysql2Model2.establish_connection(mysql2_opts)
+connection = Mysql2Model2.connection.instance_variable_get "@connection"
+connection.query_options[:cast_dates] = false
+connection.query_options[:cast_datetimes] = false
+
+Benchmark.bmbm do |x|
+ x.report "Mysql2 (with auto casting, no attr access)" do
+ number_of.times do
+ Mysql2Model.all(:limit => 1000)
+ end
+ end
+
+ x.report "Mysql2 (with lazy casting, no attr access)" do
+ number_of.times do
+ Mysql2Model2.all(:limit => 1000)
+ end
+ end
+
+ x.report "Mysql (with lazy casting, no attr access)" do
+ MysqlModel.establish_connection(mysql_opts)
+ number_of.times do
+ MysqlModel.all(:limit => 1000)
+ end
+ end
+end
+
+GC.start
+puts
+puts
+Benchmark.bmbm do |x|
+ x.report "Mysql2 (with auto casting, read date/datetime/timestamp attrs)" do
+ number_of.times do
+ Mysql2Model.all(:limit => 1000).each{ |r|
+ r.date_test
+ r.date_time_test
+ r.timestamp_test
+ }
+ end
+ end
+
+ x.report "Mysql2 (with lazy casting, read date/datetime/timestamp attrs)" do
+ number_of.times do
+ Mysql2Model2.all(:limit => 1000).each{ |r|
+ r.date_test
+ r.date_time_test
+ r.timestamp_test
+ }
+ end
+ end
+
+ x.report "Mysql (with lazy casting, read date/datetime/timestamp attrs)" do
+ MysqlModel.establish_connection(mysql_opts)
+ number_of.times do
+ MysqlModel.all(:limit => 1000).each{ |r|
+ r.date_test
+ r.date_time_test
+ r.timestamp_test
+ }
+ end
+ end
+end
+
+GC.start
+puts
+puts
Benchmark.bmbm do |x|
- x.report "Mysql2" do
- Mysql2Model.establish_connection(mysql2_opts)
+ x.report "Mysql2 (with auto casting, read all attrs)" do
number_of.times do
Mysql2Model.all(:limit => 1000).each{ |r|
r.attributes.keys.each{ |k|
@@ -38,7 +108,17 @@ class MysqlModel < ActiveRecord::Base
end
end
- x.report "Mysql" do
+ x.report "Mysql2 (with lazy casting, read all attrs)" do
+ number_of.times do
+ Mysql2Model2.all(:limit => 1000).each{ |r|
+ r.attributes.keys.each{ |k|
+ r.send(k.to_sym)
+ }
+ }
+ end
+ end
+
+ x.report "Mysql (with lazy casting, read all attrs)" do
MysqlModel.establish_connection(mysql_opts)
number_of.times do
MysqlModel.all(:limit => 1000).each{ |r|

0 comments on commit 7325884

Please sign in to comment.