Class: Bullshit::CaseMethod

Inherits:
Struct
  • Object
show all
Defined in:
lib/bullshit.rb,
lib/bullshit.rb

Overview

This class’ instance represents a method to be benchmarked.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#caseObject

Returns the value of attribute case

Returns:

  • (Object)

    the current value of case



410
411
412
# File 'lib/bullshit.rb', line 410

def case
  @case
end

#clockObject

Returns the value of attribute clock

Returns:

  • (Object)

    the current value of clock



410
411
412
# File 'lib/bullshit.rb', line 410

def clock
  @clock
end

#commentObject

The comment for this method.



421
422
423
# File 'lib/bullshit.rb', line 421

def comment
  @comment
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



410
411
412
# File 'lib/bullshit.rb', line 410

def name
  @name
end

Instance Method Details

#after_nameObject

Return the after_name, e. g. “after_foo”.



441
442
443
# File 'lib/bullshit.rb', line 441

def after_name
  'after_' + short_name
end

#after_runObject

Call after method of this CaseMethod after benchmarking it.



464
465
466
467
468
469
# File 'lib/bullshit.rb', line 464

def after_run
  if self.case.respond_to? after_name
    $DEBUG and warn "Calling #{after_name}."
    self.case.__send__(after_name)
  end
end

#before_nameObject

Return the before_name, e. g. “before_foo”.



436
437
438
# File 'lib/bullshit.rb', line 436

def before_name
  'before_' + short_name
end

#before_runObject

Call before method of this CaseMethod before benchmarking it.



456
457
458
459
460
461
# File 'lib/bullshit.rb', line 456

def before_run
  if self.case.respond_to? before_name
    $DEBUG and warn "Calling #{before_name}."
    self.case.__send__(before_name)
  end
end

#cover?(other) ⇒ Boolean

Return true if this CaseMethod#clock covers other.clock.

Returns:

  • (Boolean)


451
452
453
# File 'lib/bullshit.rb', line 451

def cover?(other)
  clock.cover?(other.clock)
end

#file_path(type = nil, suffix = '.dat') ⇒ Object

Return the file name for type with suffix (if any) for this clock.



472
473
474
475
476
477
478
# File 'lib/bullshit.rb', line 472

def file_path(type = nil, suffix = '.dat')
  name = self.case.class.benchmark_name.dup
  name << '#' << short_name
  type and name << '-' << type
  name << suffix
  File.expand_path(name, self.case.class.output_dir)
end

#load(fp = file_path) ⇒ Object

Load the data of file fp into this clock.



481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/bullshit.rb', line 481

def load(fp = file_path)
  self.clock = self.case.class.clock.new self
  $DEBUG and warn "Loading '#{fp}' into clock."
  File.open(fp, 'r') do |f|
    f.each do |line|
      line.chomp!
      line =~ /^\s*#/ and next
      clock << line.split(/\t/)
    end
  end
  self
rescue Errno::ENOENT
end

#long_nameObject Also known as: to_s

Returns the long_name of this CaseMethod of the form Foo#bar.



424
425
426
427
428
# File 'lib/bullshit.rb', line 424

def long_name
  result = "#{self.case}##{short_name}"
  result = "#{result} (#{comment})" if comment
  result
end

#setup_nameObject

Return the setup_name, e. g. “setup_foo”.



431
432
433
# File 'lib/bullshit.rb', line 431

def setup_name
  'setup_' + short_name
end

#short_nameObject

Return the short name of this CaseMethod instance, that is without the “benchmark_” prefix, e. g. “foo”.



416
417
418
# File 'lib/bullshit.rb', line 416

def short_name
  @short_name ||= name.sub(/\Abenchmark_/, '')
end

#teardown_nameObject

Return the teardown_name, e. g. “teardown_foo”.



446
447
448
# File 'lib/bullshit.rb', line 446

def teardown_name
  'teardown_' + short_name
end