Class: Object::WithBenchmark::BenchmarkProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/vex/base/object/with_benchmark.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, *args) ⇒ BenchmarkProxy

Returns a new instance of BenchmarkProxy.


6
7
8
9
10
11
12
13
14
# File 'lib/vex/base/object/with_benchmark.rb', line 6

def initialize(host, *args)
  @host = host

  if args.length == 1 && args.first.is_a?(String)
    @out, @label = nil, args.first
  else 
    @out, @label = *args
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object (private)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vex/base/object/with_benchmark.rb', line 31

def method_missing(*args, &block)
  result = ex = nil

  realtime = Benchmark.realtime do
    begin
      result = @host.__send__(*args, &block)
    rescue
      ex = $!
    end
  end

  msg = "#{@label || "benchmarked"}: #{ex && "EXCEPTION #{ex} after "}#{"%.2f secs" % realtime}"

  report(msg)

  raise ex if ex
  result
end