Class: PgTagsOn::Benchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_tags_on/benchmark/benchmark.rb

Overview

Performs benchmarking for a field, on an existing set of data.

Instance Method Summary collapse

Constructor Details

#initialize(klass, field) ⇒ Benchmark

Returns a new instance of Benchmark.



6
7
8
9
# File 'lib/pg_tags_on/benchmark/benchmark.rb', line 6

def initialize(klass, field)
  @klass = klass
  @field = field
end

Instance Method Details

#callObject



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
# File 'lib/pg_tags_on/benchmark/benchmark.rb', line 11

def call
  tags = Entity.send(field).all.limit(5).pluck(:name)

  ::Benchmark.bmbm do |b|
    b.report('Tags.one') do
      Entity.where(field => Tags.one(tags.first)).all.to_a
    end
    b.report('Tags.eq') do
      Entity.where(field => Tags.eq(tags[0..1])).all.to_a
    end
    b.report('Tags.any') do
      Entity.where(field => Tags.any(tags)).all.to_a
    end
    b.report('Tags.all') do
      Entity.where(field => Tags.all(tags)).all.to_a
    end
    b.report('Tags.in') do
      Entity.where(field => Tags.in(tags)).all.to_a
    end
    b.report('Entity.tags.all') do
      Entity.send(field).all.to_a
    end
    b.report('Entity.tags.taggings') do
      Entity.send(field).taggings.all.to_a
    end
    b.report('Entity.tags.create') do
      Entity.send(field).create('new-tag')
    end
    b.report("Entity.tags.update") do
      Entity.send(field).update(tags.pop, tags[0]+tags[1])
    end
    b.report("Entity.tags.delete") do
      Entity.send(field).delete(tags.pop)
    end
  end
end