Class: Benchmark::Memory::Job::Task
- Inherits:
-
Object
- Object
- Benchmark::Memory::Job::Task
- Defined in:
- lib/benchmark/memory/job/task.rb
Overview
Hold a labelled job for later measurement.
Instance Attribute Summary collapse
-
#action ⇒ #call
readonly
The code to be measured.
-
#label ⇒ #to_s
readonly
The label for the benchmark.
Instance Method Summary collapse
-
#call ⇒ Measurement
Call the action and report on its memory usage.
-
#initialize(label, action) ⇒ Task
constructor
Instantiate a job task for later measurement.
Constructor Details
#initialize(label, action) ⇒ Task
Instantiate a job task for later measurement.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/benchmark/memory/job/task.rb', line 15 def initialize(label, action) unless action.respond_to?(:call) fail( ArgumentError, "Invalid action (#{@action.inspect} does not respond to call)" ) end @label = label @action = action end |
Instance Attribute Details
#action ⇒ #call (readonly)
Returns The code to be measured.
28 29 30 |
# File 'lib/benchmark/memory/job/task.rb', line 28 def action @action end |
#label ⇒ #to_s (readonly)
Returns The label for the benchmark.
31 32 33 |
# File 'lib/benchmark/memory/job/task.rb', line 31 def label @label end |
Instance Method Details
#call ⇒ Measurement
Call the action and report on its memory usage.
36 37 38 39 40 |
# File 'lib/benchmark/memory/job/task.rb', line 36 def call result = while_measuring_memory_usage { action.call } Measurement.from_result(result) end |