class Benchmarker::Scope

Public Class Methods

new(bm=nil) click to toggle source
# File lib/benchmarker.rb, line 446
def initialize(bm=nil)
  @__bm = bm
end

Public Instance Methods

after(&block) click to toggle source
# File lib/benchmarker.rb, line 487
def after(&block)
  #; [!05up6] defines 'after' hook.
  @__bm.define_hook(:after, &block)
end
after_all(&block) click to toggle source
# File lib/benchmarker.rb, line 497
def after_all(&block)
  #; [!z7xop] defines 'after_all' hook.
  @__bm.define_hook(:after_all, &block)
end
assert(expr, errmsg) click to toggle source
# File lib/benchmarker.rb, line 507
def assert(expr, errmsg)
  #; [!a0c7e] do nothing if assertion succeeded.
  #; [!5vmbc] raises error if assertion failed.
  #; [!7vt5l] puts newline if assertion failed.
  return if expr
  puts ""
  raise ValidationFailed, errmsg
rescue => exc
  #; [!mhw59] makes error backtrace compact.
  exc.backtrace.reject! {|x| x =~ /[\/\\:]benchmarker\.rb.*:/ }
  raise
end
assert_eq(actual, expected, errmsg=nil) click to toggle source
# File lib/benchmarker.rb, line 474
def assert_eq(actual, expected, errmsg=nil)
  #; [!8m6bh] do nothing if ectual == expected.
  #; [!f9ey6] raises error unless actual == expected.
  return if actual == expected
  errmsg ||= "#{actual.inspect} == #{expected.inspect}: failed."
  assert false, errmsg
end
before(&block) click to toggle source
# File lib/benchmarker.rb, line 482
def before(&block)
  #; [!2ir4q] defines 'before' hook.
  @__bm.define_hook(:before, &block)
end
before_all(&block) click to toggle source
# File lib/benchmarker.rb, line 492
def before_all(&block)
  #; [!1oier] defines 'before_all' hook.
  @__bm.define_hook(:before_all, &block)
end
empty_task(code=nil, binding=nil, &block) click to toggle source
# File lib/benchmarker.rb, line 469
def empty_task(code=nil, binding=nil, &block)
  #; [!ycoch] creates new empty-loop task object.
  return task(nil, code, binding, &block)
end
report(name, code=nil, binding=nil, tag: nil, skip: nil, &block)
Alias for: task
task(name, code=nil, binding=nil, tag: nil, skip: nil, &block) click to toggle source
# File lib/benchmarker.rb, line 450
def task(name, code=nil, binding=nil, tag: nil, skip: nil, &block)
  #; [!843ju] when code argument provided...
  if code
    #; [!bwfak] code argument and block argument are exclusive.
    ! block_given?()  or
      raise TaskError, "task(#{name.inspect}): cannot accept #{code.class} argument when block argument given."
    #; [!4dm9q] generates block argument if code argument passed.
    location = caller_locations(1, 1).first
    defcode  = "proc do #{(code+';') * N_REPEAT} end"   # repeat code 100 times
    binding ||= ::TOPLEVEL_BINDING
    block = eval defcode, binding, location.path, location.lineno+1
  end
  #; [!kh7r9] define empty-loop task if name is nil.
  return @__bm.define_empty_task(code, tag: tag, skip: skip, &block) if name.nil?
  #; [!j6pmr] creates new task object.
  return @__bm.define_task(name, code, tag: tag, skip: skip, &block)
end
Also aliased as: report
validate(&block) click to toggle source
# File lib/benchmarker.rb, line 502
def validate(&block)
  #; [!q2aev] defines validator.
  return @__bm.define_hook(:validate, &block)
end