Guest User

Untitled

a guest
May 2nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. require 'rubygems'
  2. require 'mysql'
  3. require 'thread'
  4. require 'benchmark'
  5.  
  6. DB_CONFIG = {
  7. :username => 'root',
  8. :password => '',
  9. :host => '127.0.0.1',
  10. :db => 'SOME_DB_NAME'
  11. }
  12.  
  13. ITERATIONS=6
  14.  
  15. def execute_query
  16. conn = Mysql.new(DB_CONFIG[:host], DB_CONFIG[:username], DB_CONFIG[:password], DB_CONFIG[:db], 3306, nil, nil)
  17. res = conn.query("select sleep(1) from dual;")
  18. res.free
  19. conn.close
  20. end
  21.  
  22. puts "Iterations:#{ITERATIONS} SQL: #{SQL_STMT}"
  23. puts "Serial: " + Benchmark.measure { ITERATIONS.times {execute_query}}.real.to_s
  24. threads = []
  25. ITERATIONS.times { threads << Thread.new { execute_query} }
  26. puts "Multi-threaded: " + Benchmark.measure { threads.collect{|t| t.join}}.real.to_s
Add Comment
Please, Sign In to add comment