Sha256: 9d87668a4f8cacb3e5d24a7e528e3698bd4b45291871cc52a48d27ab6d0a5143

Contents?: true

Size: 802 Bytes

Versions: 1

Compression:

Stored size: 802 Bytes

Contents

require 'benchmark'

module BootPolish
  class NestedBenchmark

    attr_accessor :visitor

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

    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

    private
    
    def before_call 
      @visitor.descend
    end

    def after_call(method, time_to_run, exception = nil)
      if exception
        @visitor.exception(method, exception)
      else
        @visitor.benchmark(method, time_to_run)
      end

      @visitor.ascend
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
boot_polish-0.0.1 lib/boot_polish/nested_benchmark.rb