Sha256: 71b37ec689bb43b7fab4d29f33b08de1595431d1ac61c4ac98fdcd70dfa89f6b

Contents?: true

Size: 968 Bytes

Versions: 48

Compression:

Stored size: 968 Bytes

Contents

# encoding: UTF-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'active_record'

mysql2_opts = {
  :adapter => 'mysql2',
  :database => 'test',
  :pool => 25
}
ActiveRecord::Base.establish_connection(mysql2_opts)
x = Benchmark.realtime do
  threads = []
  25.times do
    threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
  end
  threads.each {|t| t.join }
end
puts x

mysql2_opts = {
  :adapter => 'mysql',
  :database => 'test',
  :pool => 25
}
ActiveRecord::Base.establish_connection(mysql2_opts)
x = Benchmark.realtime do
  threads = []
  25.times do
    threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
  end
  threads.each {|t| t.join }
end
puts x

# these results are similar on 1.8.7, 1.9.2 and rbx-head
#
# $ bundle exec ruby benchmarks/threaded.rb
# 1.0774750709533691
#
# and using the mysql gem
# 25.099437952041626

Version data entries

48 entries across 48 versions & 5 rubygems

Version Path
mysql2-0.2.18-x86-mingw32 benchmark/threaded.rb
mysql2-0.2.18 benchmark/threaded.rb
mysql2-0.3.10 benchmark/threaded.rb
mysql2-0.2.17 benchmark/threaded.rb
mysql2-0.2.16 benchmark/threaded.rb
mysql2-0.3.9 benchmark/threaded.rb
mysql2-0.2.16-x86-mswin32-60 benchmark/threaded.rb
mysql2-0.2.16-x86-mingw32 benchmark/threaded.rb
mysql2-0.3.9-x86-mswin32-60 benchmark/threaded.rb
mysql2-0.3.9-x86-mingw32 benchmark/threaded.rb
mysql2-0.2.15-x86-mswin32-60 benchmark/threaded.rb
mysql2-0.3.8 benchmark/threaded.rb
mysql2-0.2.14 benchmark/threaded.rb
mysql2-0.3.7 benchmark/threaded.rb
mysql2-0.2.13 benchmark/threaded.rb
mysql2-0.2.12 benchmark/threaded.rb
mysql2-0.3.6 benchmark/threaded.rb
mysql2-0.2.11 benchmark/threaded.rb
mysql2-0.3.5 benchmark/threaded.rb
mysql2-0.2.10 benchmark/threaded.rb