class Benchmarker::Task

Attributes

block[R]
name[R]
skip[R]
tag[R]

Public Class Methods

new(name, code=nil, tag: nil, skip: nil, &block) click to toggle source
# File lib/benchmarker.rb, line 533
def initialize(name, code=nil, tag: nil, skip: nil, &block)
  @name  = name
  @code  = code
  @tag   = tag
  @skip  = skip    # reason to skip
  @block = block
end

Public Instance Methods

has_code?() click to toggle source
# File lib/benchmarker.rb, line 543
def has_code?
  return !!@code
end
invoke(loop=1) { |ret, name, tag| ... } click to toggle source
# File lib/benchmarker.rb, line 551
def invoke(loop=1, &validator)
  #; [!s2f6v] when task block is build from repeated code...
  if @code
    n_repeat = N_REPEAT    # == 100
    #; [!i2r8o] error when number of loop is less than 100.
    loop >= n_repeat  or
      raise TaskError, "task(#{@name.inspect}): number of loop (=#{loop}) should be >= #{n_repeat}, but not."
    #; [!kzno6] error when number of loop is not a multiple of 100.
    loop % n_repeat == 0  or
      raise TaskError, "task(#{@name.inspect}): number of loop (=#{loop}) should be a multiple of #{n_repeat}, but not."
    #; [!gbukv] changes number of loop to 1/100.
    loop = loop / n_repeat
  end
  #; [!frq25] kicks GC before calling task block.
  GC.start()
  #; [!tgql6] invokes block N times.
  block = @block
  t1 = Process.times
  start_t = Time.now
  while (loop -= 1) >= 0
    ret = block.call()
  end
  end_t = Time.now
  t2 = Process.times
  #; [!zw4kt] yields validator with result value of block.
  yield ret, @name, @tag if block_given?()
  #; [!9e5pr] returns TimeSet object.
  user  = t2.utime - t1.utime
  sys   = t2.stime - t1.stime
  total = user + sys
  real  = end_t - start_t
  return TimeSet.new(user, sys, total, real)
end
skip?() click to toggle source
# File lib/benchmarker.rb, line 547
def skip?
  return !!@skip
end