public
Last active

  • Download Gist
AR vs DM vs Sequel benchmark
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
require 'benchmark'
 
Q = "select * from bet limit 3000"
 
ARi = Proc.new {
require 'activerecord'
ActiveRecord::Base.establish_connection(:adapter => "postgresql",
:host => "localhost",
:username => "betscan",
:password => "abcd1234",
:database => "betloader")
class BetAR < ActiveRecord::Base
set_table_name "bet"
end
}
 
DMi = Proc.new {
require 'datamapper'
DataMapper.setup(:default, 'postgres://betscan:abcd1234@localhost/betloader')
class BetDM
include DataMapper::Resource
storage_names[:default] = 'bet'
property :id, Serial
property :time, DateTime
property :bookmaker_id, Integer
property :event_id, Integer
end
}
SQi = Proc.new {
require 'sequel'
DB = Sequel.connect('postgres://betscan:abcd1234@localhost/betloader')
}
 
Benchmark.bm do |x|
x.report("ARi", &ARi)
x.report("DMi", &DMi)
x.report("SQi", &SQi)
end
 
ARp = Proc.new {
data = BetAR.find_by_sql Q
#data = ActiveRecord::Base.connection.execute Q
nused = nil
data.each{|e|
nused = "#{e.time}+#{e.id}+#{e.bookmaker_id}+#{e.event_id}"
}
p nused
}
 
DMp = Proc.new {
data = BetDM.find_by_sql Q
nused = nil
data.each{|e|
nused = "#{e.time}+#{e.id}+#{e.bookmaker_id}+#{e.event_id}"
}
p nused
}
 
SQp = Proc.new {
data = DB[Q]
nused = nil
data.each{|e|
nused = "#{e[:time]}+#{e[:id]}+#{e[:bookmaker_id]}+#{e[:event_id]}"
}
p nused
}
 
Benchmark.bm do |x|
 
x.report("DM", &DMp)
x.report("SQ", &SQp)
x.report("AR", &ARp)
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.