Class: BootPolish::NestedBenchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/boot_polish/nested_benchmark.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(visitor = nil) ⇒ NestedBenchmark

Returns a new instance of NestedBenchmark.



8
9
10
# File 'lib/boot_polish/nested_benchmark.rb', line 8

def initialize(visitor = nil)
  @visitor = visitor || DefaultRenderer.new
end

Instance Attribute Details

#visitorObject

Returns the value of attribute visitor.



6
7
8
# File 'lib/boot_polish/nested_benchmark.rb', line 6

def visitor
  @visitor
end

Instance Method Details

#nest(method, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/boot_polish/nested_benchmark.rb', line 12

def nest method, &block
  result = nil

  before_call

  time_to_run = Benchmark.measure do
    begin
      result = yield
    rescue Exception => e
      after_call(method, nil, e)
      raise e
    end
  end

  after_call(method, time_to_run)

  result
end