Created
April 27, 2009 03:14
-
-
Save BJClark/102304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "ruby-prof" | |
require "mysql" | |
def print_profile(result) | |
if result | |
printer = RubyProf::FlatPrinter.new(result) | |
printer.print(STDOUT, 0) | |
else | |
puts "There are no result to print." | |
end | |
end | |
#result = RubyProf.profile do | |
# #assign_many(cache, num_times, 'a'*16) | |
# begin | |
# # connect to the MySQL server | |
# dbh = Mysql.real_connect("localhost", "root", "", "dht_test") | |
# # get server version string and display it | |
# puts "Server version: " + dbh.get_server_info | |
# 1000000.times do | |
# dbh.query("INSERT INTO dht (value) VALUES ('#{'a'*16}')") | |
# end | |
# | |
# rescue Mysql::Error => e | |
# puts "Error code: #{e.errno}" | |
# puts "Error message: #{e.error}" | |
# puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate") | |
# ensure | |
# # disconnect from server | |
# dbh.close if dbh | |
# end | |
#end | |
#result = RubyProf.profile do | |
# #assign_many(cache, num_times, 'a'*16) | |
# begin | |
# # connect to the MySQL server | |
# dbh = Mysql.real_connect("localhost", "root", "", "dht_test") | |
# # get server version string and display it | |
# puts "Server version: " + dbh.get_server_info | |
# 1000000.times do |num| | |
# dbh.query("SELECT * from dht where id = #{num}") | |
# end | |
# | |
# rescue Mysql::Error => e | |
# puts "Error code: #{e.errno}" | |
# puts "Error message: #{e.error}" | |
# puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate") | |
# ensure | |
# # disconnect from server | |
# dbh.close if dbh | |
# end | |
#end | |
num_sets = 100 | |
items_in_set = 100 | |
about_text = <<-EOF | |
If you liked To Kill A Mockingbird you love Summer Lightning and the irrepressible cigarette-smoking, redheaded truant named Terry, called Little Hawk by his friend, old McCree. Together they prowl the Everglades in search of rattlesnakes, epiphytes, a | |
EOF | |
result = RubyProf.profile do | |
#assign_many(cache, num_times, 'a'*16) | |
begin | |
# connect to the MySQL server | |
dbh = Mysql.real_connect("mysql://localhost:3306", "root", "", "dht_test") | |
# get server version string and display it | |
puts "Server version: " + dbh.get_server_info | |
dbh.query("LOCK TABLES abouts WRITE;") | |
num_sets.times do |set_num| | |
query = "INSERT INTO abouts (page_id, href, paragraph) VALUES " | |
query_values = [] | |
items_in_set.times do |item_num| | |
query_values << "(#{((set_num * items_in_set) + item_num)}, 'https://shop.strato.de/epages/61424592.sf/de_DE/?ObjectPath=/Shops/61424592&ViewAction=ViewRegistration', '#{about_text}')" | |
end | |
query << query_values.join(", ") | |
query << ";" | |
dbh.query(query) | |
end | |
dbh.query("UNLOCK TABLES;") | |
rescue Mysql::Error => e | |
puts "Error code: #{e.errno}" | |
puts "Error message: #{e.error}" | |
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate") | |
ensure | |
# disconnect from server | |
dbh.close if dbh | |
end | |
end | |
print_profile(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment