Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update AR's performance script #63

Merged
2 commits merged into from

1 participant

@miloops

No description provided.

@jake3030 jake3030 referenced this pull request from a commit in jake3030/rails
@alk alk establish mysql connection before dropping database
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#63 state:committed]
a0bc480
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 2 deletions.
  1. +19 −2 activerecord/examples/performance.rb
View
21 activerecord/examples/performance.rb
@@ -60,7 +60,7 @@ def self.feel(exhibits) exhibits.each { |e| e.feel } end
sqlfile = "#{__DIR__}/performance.sql"
if File.exists?(sqlfile)
- mysql_bin = %w[mysql mysql5].select { |bin| `which #{bin}`.length > 0 }
+ mysql_bin = %w[mysql mysql5].detect { |bin| `which #{bin}`.length > 0 }
`#{mysql_bin} -u #{conn[:username]} #{"-p#{conn[:password]}" unless conn[:password].blank?} #{conn[:database]} < #{sqlfile}`
else
puts 'Generating data...'
@@ -90,7 +90,7 @@ def self.feel(exhibits) exhibits.each { |e| e.feel } end
)
end
- mysqldump_bin = %w[mysqldump mysqldump5].select { |bin| `which #{bin}`.length > 0 }
+ mysqldump_bin = %w[mysqldump mysqldump5].detect { |bin| `which #{bin}`.length > 0 }
`#{mysqldump_bin} -u #{conn[:username]} #{"-p#{conn[:password]}" unless conn[:password].blank?} #{conn[:database]} exhibits users > #{sqlfile}`
end
@@ -174,6 +174,23 @@ def self.feel(exhibits) exhibits.each { |e| e.feel } end
ar { ActiveRecord::Base.connection.execute("Select * from exhibits where id = #{(rand * 1000 + 1).to_i}") }
end
+ report 'Model.find(id)' do
+ id = Exhibit.first.id
+ ar { Exhibit.find(id) }
+ end
+
+ report 'Model.find_by_sql' do
+ ar { Exhibit.find_by_sql("SELECT * FROM exhibits WHERE id = #{(rand * 1000 + 1).to_i}").first }
+ end
+
+ report 'Model.log', (TIMES * 10) do
+ ar { Exhibit.connection.send(:log, "hello", "world") {} }
+ end
+
+ report 'AR.execute(query)', (TIMES / 2) do
+ ar { ActiveRecord::Base.connection.execute("Select * from exhibits where id = #{(rand * 1000 + 1).to_i}") }
+ end
+
summary 'Total'
end
Something went wrong with that request. Please try again.