Class: Benchmark::Memory::Job::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark/memory/job/task.rb

Overview

Hold a labelled job for later measurement.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, action) ⇒ Task

Instantiate a job task for later measurement.

Parameters:

  • label (#to_s)

    The label for the benchmark.

  • action (#call)

    The code to be measured.

Raises:

  • (ArgumentError)

    if the action does not respond to #call.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/benchmark/memory/job/task.rb', line 17

def initialize(label, action)
  unless action.respond_to?(:call)
    raise(
      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.

Returns:

  • (#call)

    The code to be measured.



30
31
32
# File 'lib/benchmark/memory/job/task.rb', line 30

def action
  @action
end

#label#to_s (readonly)

Returns The label for the benchmark.

Returns:

  • (#to_s)

    The label for the benchmark.



33
34
35
# File 'lib/benchmark/memory/job/task.rb', line 33

def label
  @label
end

Instance Method Details

#callMeasurement

Call the action and report on its memory usage.

Returns:

  • (Measurement)

    the memory usage measurement of the code.



38
39
40
41
42
# File 'lib/benchmark/memory/job/task.rb', line 38

def call
  result = while_measuring_memory_usage { action.call }

  Measurement.from_result(result)
end