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



1367
1368
1369
# File 'lib/bullshit.rb', line 1367

def case
  @case
end

#clockObject

Returns the value of attribute clock

Returns:

  • (Object)

    the current value of clock



1367
1368
1369
# File 'lib/bullshit.rb', line 1367

def clock
  @clock
end

#commentObject

The comment for this method.



1378
1379
1380
# File 'lib/bullshit.rb', line 1378

def comment
  @comment
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



1367
1368
1369
# File 'lib/bullshit.rb', line 1367

def name
  @name
end

Instance Method Details

#after_nameObject

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



1398
1399
1400
# File 'lib/bullshit.rb', line 1398

def after_name
  'after_' + short_name
end

#after_runObject

Call after method of this CaseMethod after benchmarking it.



1421
1422
1423
1424
1425
1426
# File 'lib/bullshit.rb', line 1421

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”.



1393
1394
1395
# File 'lib/bullshit.rb', line 1393

def before_name
  'before_' + short_name
end

#before_runObject

Call before method of this CaseMethod before benchmarking it.



1413
1414
1415
1416
1417
1418
# File 'lib/bullshit.rb', line 1413

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)


1408
1409
1410
# File 'lib/bullshit.rb', line 1408

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.



1429
1430
1431
1432
1433
1434
1435
# File 'lib/bullshit.rb', line 1429

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.



1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
# File 'lib/bullshit.rb', line 1438

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
end

#long_nameObject

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



1381
1382
1383
1384
1385
# File 'lib/bullshit.rb', line 1381

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”.



1388
1389
1390
# File 'lib/bullshit.rb', line 1388

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”.



1373
1374
1375
# File 'lib/bullshit.rb', line 1373

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

#teardown_nameObject

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



1403
1404
1405
# File 'lib/bullshit.rb', line 1403

def teardown_name
  'teardown_' + short_name
end