267942571862781dd912de6482a35f46

first of three benchmarks, expected AR to be slowest but it was fastest - why?

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
require 'rubygems'
require 'active_record'
require 'benchmark'

ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'perf_ar.db'

# set up ActiveRecord
class ArItem < ActiveRecord::Base
  set_table_name 'items'
end

# created schema and data
class NewItem < ActiveRecord::Migration
  def self.up
    create_table :items do |t|
      t.column :name, :string
      t.column :description, :text
      t.column :active, :boolean
      t.column :created_at, :datetime
    end
  end
  def self.down
    drop_table :items
  end
end
NewItem.up

1000.times do |i|
  ArItem.create(:name => "record_#{i}", :description => "test record", :active => i.remainder(3).zero?)
end

# run benchmarks
Benchmark.bmbm do |x|
  
  x.report('active_record single-thread') do
    100.times do
      ArItem.find(:all, :conditions => ["active = ?", false])
    end
  end
  
  x.report('active_record threaded') do
    ActiveRecord::Base.allow_concurrency = true
    threads = []
    10.times do
      t = Thread.new do
        10.times do
          ArItem.find(:all, :conditions => ["active = ?", false])
        end
      end
      threads.push(t)
    end
    threads.each { |t| t.join }
  end
  
end
ActiveRecord::Base.verify_active_connections!
NewItem.down

Refactorings

No refactoring yet !

E2e32d0e0caf2e83721b7ba638cb4620

jaifisiorie

February 16, 2010, February 16, 2010 11:16, permalink

No rating. Login to rate!

Searched for video and has casually originate the big archive of "violent" :)
Has dared to interest all maximum time :P
But they sometimes do not persuade :(
It is resulting to update video the codec
<a href=http://xarchive.if.ua/american-teen-lesbians.html>american teen lesbians</a>

Your refactoring





Format Copy from initial code

or Cancel