class Result

Attributes

all[R]
counter[R]
max[R]
message[R]
middle[R]
min[R]
msg[R]
output[R]
type[R]

Public Class Methods

new( type, message ) click to toggle source
# File lib/benchify/result.rb, line 8
def initialize( type, message )
  @type = type.to_sym
  @msg  = message
  @all  = []
end

Public Instance Methods

add( start, ends ) click to toggle source
# File lib/benchify/result.rb, line 14
def add( start, ends )
  time = ends.to_f - start.to_f
  @all << time
end
create_result_message() click to toggle source
# File lib/benchify/result.rb, line 27
def create_result_message
  msg = @msg.to_s
  msg += " => "
  msg += "min: #{@min} #{@type} | max: #{@max} #{@type} | middle: #{@middle} #{@type}"
end
get() click to toggle source
# File lib/benchify/result.rb, line 19
def get
  @counter = @all.size
  @min     = get_by_type @all.min
  @max     = get_by_type @all.max
  @middle  = get_by_type ( @max - ( (@max - @min) / 2 ) )
  @output  = create_result_message
end

Private Instance Methods

get_by_type( time ) click to toggle source
# File lib/benchify/result.rb, line 35
def get_by_type( time )
  case @type
    when :min then x = (time / 360).round(2)
    when :ms  then x = (time * 1000).round(5)
    when :h   then x = (time / 60).round(2)
    else  x = time.round(4)
  end
  return x
end