Class: Bullshit::CaseMethod
- Inherits:
-
Struct
- Object
- Struct
- Bullshit::CaseMethod
- Defined in:
- lib/bullshit.rb,
lib/bullshit.rb
Overview
This class’ instance represents a method to be benchmarked.
Instance Attribute Summary collapse
-
#case ⇒ Object
Returns the value of attribute case.
-
#clock ⇒ Object
Returns the value of attribute clock.
-
#comment ⇒ Object
The comment for this method.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#after_name ⇒ Object
Return the after_name, e.
-
#after_run ⇒ Object
Call after method of this CaseMethod after benchmarking it.
-
#before_name ⇒ Object
Return the before_name, e.
-
#before_run ⇒ Object
Call before method of this CaseMethod before benchmarking it.
-
#cover?(other) ⇒ Boolean
Return true if this CaseMethod#clock covers other.clock.
-
#file_path(type = nil, suffix = '.dat') ⇒ Object
Return the file name for
typewithsuffix(if any) for this clock. -
#load(fp = file_path) ⇒ Object
Load the data of file
fpinto this clock. -
#long_name ⇒ Object
(also: #to_s)
Returns the long_name of this CaseMethod of the form Foo#bar.
-
#setup_name ⇒ Object
Return the setup_name, e.
-
#short_name ⇒ Object
Return the short name of this CaseMethod instance, that is without the “benchmark_” prefix, e.
-
#teardown_name ⇒ Object
Return the teardown_name, e.
Instance Attribute Details
#case ⇒ Object
Returns the value of attribute case
410 411 412 |
# File 'lib/bullshit.rb', line 410 def case @case end |
#clock ⇒ Object
Returns the value of attribute clock
410 411 412 |
# File 'lib/bullshit.rb', line 410 def clock @clock end |
#comment ⇒ Object
The comment for this method.
421 422 423 |
# File 'lib/bullshit.rb', line 421 def comment @comment end |
#name ⇒ Object
Returns the value of attribute name
410 411 412 |
# File 'lib/bullshit.rb', line 410 def name @name end |
Instance Method Details
#after_name ⇒ Object
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_run ⇒ Object
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_name ⇒ Object
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_run ⇒ Object
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.
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.(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_name ⇒ Object 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_name ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
Return the teardown_name, e. g. “teardown_foo”.
446 447 448 |
# File 'lib/bullshit.rb', line 446 def teardown_name 'teardown_' + short_name end |