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



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.

Returns:

  • (#call)

    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.

Returns:

  • (#to_s)

    The label for the benchmark.



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

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.



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