require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'pg' gem 'mini_sql', path: '../' gem 'activesupport' gem 'activerecord' gem 'activemodel' gem 'memory_profiler' gem 'benchmark-ips' gem 'sequel' gem 'sequel_pg', require: 'sequel' end require 'sequel' require 'active_record' require 'memory_profiler' require 'benchmark/ips' require 'mini_sql' ActiveRecord::Base.establish_connection( :adapter => "postgresql", :database => "test_db" ) DB = Sequel.postgres('test_db') pg = ActiveRecord::Base.connection.raw_connection pg.async_exec < 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 pg") do |n| while n > 0 wide_topic_pg 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 Benchmark.ips do |r| r.report("ar select title id") do |n| while n > 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("pg select title id") do |n| while n > 0 pg_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 # Calculating ------------------------------------- # wide topic ar 2.383k (± 4.9%) i/s - 12.005k in 5.050490s # wide topic sequel 3.449k (± 3.2%) i/s - 17.591k in 5.104951s # wide topic pg 7.345k (± 1.2%) i/s - 37.352k in 5.086015s # wide topic mini sql 7.536k (± 1.4%) i/s - 38.220k in 5.072834s # # Comparison: # wide topic mini sql: 7535.8 i/s # wide topic pg: 7345.1 i/s - same-ish: difference falls within error # wide topic sequel: 3449.4 i/s - 2.18x slower # wide topic ar: 2382.9 i/s - 3.16x slower # # Calculating ------------------------------------- # ar select title id 131.572 (± 3.8%) i/s - 658.000 in 5.008231s # ar select title id pluck # 696.233 (± 3.7%) i/s - 3.519k in 5.061335s # sequel title id select # 916.841 (± 3.7%) i/s - 4.655k in 5.084499s # pg select title id 1.002k (± 4.0%) i/s - 5.044k in 5.040584s # mini_sql select title id # 1.106k (± 2.4%) i/s - 5.618k in 5.084423s # sequel title id pluck # 1.181k (± 3.5%) i/s - 5.980k in 5.069815s # mini_sql query_single title id # 1.171k (± 3.1%) i/s - 5.880k in 5.025793s # # Comparison: # sequel title id pluck: 1181.0 i/s # mini_sql query_single title id: 1171.1 i/s - same-ish: difference falls within error # mini_sql select title id: 1105.6 i/s - 1.07x slower # pg select title id: 1002.2 i/s - 1.18x slower # sequel title id select: 916.8 i/s - 1.29x slower # ar select title id pluck: 696.2 i/s - 1.70x slower # ar select title id: 131.6 i/s - 8.98x slower # # to run deep analysis run # MemoryProfiler.report do # ar # end.pretty_print