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
require 'rubygems' require 'sequel' require 'benchmark' # set up Sequel Sequel::Model.db = DB = Sequel.sqlite('perf_sequel.db') class SequelItem < Sequel::Model(:items) set_schema do primary_key :id varchar :name text :description boolean :active timestamp :created_at end end # create schema and populate SequelItem.create_table! 1000.times do |i| DB[:items].insert(:name => "record_#{i}", :description => "test record", :active => i.remainder(3).zero?, :created_at => Time.now) end # run benchmarks Benchmark.bmbm do |x| x.report('sequel single-thread') do 100.times do SequelItem.where(:active => false).all end end x.report('sequel threaded') do threads = [] 10.times do t = Thread.new do 10.times do SequelItem.where(:active => false).all end end threads.push(t) end threads.each { |t| t.join } end end SequelItem.drop_table
Refactorings
No refactoring yet !
second of three, not as fast as ActiveRecord - why?