Class: Benchmarker::Task
- Inherits:
-
Object
- Object
- Benchmarker::Task
- Defined in:
- lib/benchmarker.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#skip ⇒ Object
readonly
Returns the value of attribute skip.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #has_code? ⇒ Boolean
-
#initialize(name, code = nil, tag: nil, skip: nil, &block) ⇒ Task
constructor
A new instance of Task.
- #invoke(loop = 1) {|ret, @name, @tag| ... } ⇒ Object
- #skip? ⇒ Boolean
Constructor Details
#initialize(name, code = nil, tag: nil, skip: nil, &block) ⇒ Task
Returns a new instance of Task.
534 535 536 537 538 539 540 |
# File 'lib/benchmarker.rb', line 534 def initialize(name, code=nil, tag: nil, skip: nil, &block) @name = name @code = code @tag = tag @skip = skip # reason to skip @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
542 543 544 |
# File 'lib/benchmarker.rb', line 542 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
542 543 544 |
# File 'lib/benchmarker.rb', line 542 def name @name end |
#skip ⇒ Object (readonly)
Returns the value of attribute skip.
542 543 544 |
# File 'lib/benchmarker.rb', line 542 def skip @skip end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
542 543 544 |
# File 'lib/benchmarker.rb', line 542 def tag @tag end |
Instance Method Details
#has_code? ⇒ Boolean
544 545 546 |
# File 'lib/benchmarker.rb', line 544 def has_code? return !!@code end |
#invoke(loop = 1) {|ret, @name, @tag| ... } ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/benchmarker.rb', line 552 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? ⇒ Boolean
548 549 550 |
# File 'lib/benchmarker.rb', line 548 def skip? return !!@skip end |