2010-04-15 20:00:39 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'benchmark'
|
|
|
|
require 'active_record'
|
|
|
|
|
2010-08-02 08:19:28 +00:00
|
|
|
ActiveRecord::Base.default_timezone = :local
|
2010-07-29 15:57:05 +00:00
|
|
|
ActiveRecord::Base.time_zone_aware_attributes = true
|
|
|
|
|
2010-04-21 08:31:46 +00:00
|
|
|
number_of = 10
|
2010-04-15 20:00:39 +00:00
|
|
|
mysql2_opts = {
|
|
|
|
:adapter => 'mysql2',
|
|
|
|
:database => 'test'
|
|
|
|
}
|
|
|
|
mysql_opts = {
|
|
|
|
:adapter => 'mysql',
|
|
|
|
:database => 'test'
|
|
|
|
}
|
|
|
|
|
2010-04-26 04:45:26 +00:00
|
|
|
class Mysql2Model < ActiveRecord::Base
|
|
|
|
set_table_name :mysql2_test
|
|
|
|
end
|
|
|
|
|
|
|
|
class MysqlModel < ActiveRecord::Base
|
2010-04-15 20:00:39 +00:00
|
|
|
set_table_name :mysql2_test
|
|
|
|
end
|
|
|
|
|
|
|
|
Benchmark.bmbm do |x|
|
|
|
|
x.report do
|
2010-04-26 04:45:26 +00:00
|
|
|
Mysql2Model.establish_connection(mysql2_opts)
|
2010-04-15 20:00:39 +00:00
|
|
|
puts "Mysql2"
|
|
|
|
number_of.times do
|
2010-04-26 04:45:26 +00:00
|
|
|
Mysql2Model.all(:limit => 1000).each{ |r|
|
|
|
|
r.attributes.keys.each{ |k|
|
|
|
|
r.send(k.to_sym)
|
|
|
|
}
|
|
|
|
}
|
2010-04-15 20:00:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
x.report do
|
2010-04-26 04:45:26 +00:00
|
|
|
MysqlModel.establish_connection(mysql_opts)
|
2010-04-15 20:00:39 +00:00
|
|
|
puts "Mysql"
|
|
|
|
number_of.times do
|
2010-04-26 04:45:26 +00:00
|
|
|
MysqlModel.all(:limit => 1000).each{ |r|
|
|
|
|
r.attributes.keys.each{ |k|
|
|
|
|
r.send(k.to_sym)
|
|
|
|
}
|
|
|
|
}
|
2010-04-15 20:00:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|