require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'mysql2' gem 'mini_sql', path: '../' gem 'activesupport' gem 'activerecord' gem 'activemodel' gem 'memory_profiler' gem 'benchmark-ips' gem 'sequel', github: 'jeremyevans/sequel' end require 'mysql2' require 'sequel' require 'active_record' require 'memory_profiler' require 'benchmark/ips' require 'mini_sql' ActiveRecord::Base.establish_connection( :adapter => "mysql2", :database => "test_db", :username => "root", :password => '' ) DB = Sequel.connect("mysql2://root:@localhost/test_db") mysql = ActiveRecord::Base.connection.raw_connection mysql.query < 0 ar_title_id n -= 1 end end r.report("ar select title id pluck") do |n| while n > 0 ar_title_id_pluck n -= 1 end end r.report("sequel title id select") do |n| while n > 0 sequel_select_title_id n -= 1 end end r.report("mysql select title id") do |n| while n > 0 mysql_title_id n -= 1 end end r.report("mini_sql select title id") do |n| while n > 0 mini_sql_title_id n -= 1 end end r.report("sequel title id pluck") do |n| while n > 0 sequel_pluck_title_id n -= 1 end end r.report("mini_sql query_single title id") do |n| while n > 0 mini_sql_title_id_query_single n -= 1 end end r.compare! end def wide_topic_ar Topic.first end def wide_topic_mysql r = $conn.query("select * from topics limit 1", as: :hash) row = r.first row end def wide_topic_sequel TopicSequel.first end def wide_topic_mini_sql $conn.query("select * from topics limit 1").first end Benchmark.ips do |r| r.report("wide topic ar") do |n| while n > 0 wide_topic_ar n -= 1 end end r.report("wide topic sequel") do |n| while n > 0 wide_topic_sequel n -= 1 end end r.report("wide topic mysql") do |n| while n > 0 wide_topic_mysql n -= 1 end end r.report("wide topic mini sql") do |n| while n > 0 wide_topic_mini_sql n -= 1 end end r.compare! end # Comparison: # mysql select title id: 485.0 i/s # mini_sql query_single title id: 447.2 i/s - same-ish: difference falls within error # mini_sql select title id: 417.4 i/s - 1.16x slower # sequel title id pluck: 370.2 i/s - 1.31x slower # sequel title id select: 351.0 i/s - 1.38x slower # ar select title id pluck: 317.1 i/s - 1.53x slower # ar select title id: 102.3 i/s - 4.74x slower # Comparison: # wide topic mini sql: 6768.7 i/s # wide topic mysql: 6063.9 i/s - same-ish: difference falls within error # wide topic sequel: 4908.6 i/s - same-ish: difference falls within error # wide topic ar: 2630.2 i/s - 2.57x slower