class Benchmark::Memory::Job
Encapsulate the memory measurements of reports.
Attributes
@return [Report] the full report of all measurements in the job.
@return [Array<Task>] the measurement tasks to run.
Public Class Methods
Instantiate a job for containing memory performance reports.
@param output [#puts] The output to use for showing the job results. @param quiet [Boolean] A flag for stopping output.
@return [Job]
# File lib/benchmark/memory/job.rb, line 20 def initialize(output: $stdout, quiet: false) @compare = false @full_report = Report.new @held_results = HeldResults.new @quiet = quiet @output = quiet? ? NullOutput.new : IOOutput.new(output) @tasks = [] end
Public Instance Methods
Enable output of a comparison of the different tasks.
@return [void]
# File lib/benchmark/memory/job.rb, line 47 def compare! @compare = true end
Check whether the job should do a comparison.
@return [Boolean]
# File lib/benchmark/memory/job.rb, line 40 def compare? @compare end
Enable holding results to compare between separate runs.
@param held_path [String, IO] The location to save the held results.
@return [void]
# File lib/benchmark/memory/job.rb, line 56 def hold!(held_path) @held_results.path = held_path end
Check whether the job is set to quiet.
@return [Boolean]
# File lib/benchmark/memory/job.rb, line 130 def quiet? @quiet end
Add a measurement entry to the job to measure the specified block.
@param label [String] The label for the measured code. @param block [Proc] Code the measure.
@raise [ArgumentError] if no code block is specified.
# File lib/benchmark/memory/job.rb, line 66 def report(label = "", &block) unless block_given? fail ArgumentError, "You did not specify a block for the item" end tasks.push Task.new(label, block) end
Run the job and outputs its full report.
@return [Report]
# File lib/benchmark/memory/job.rb, line 77 def run @output.put_header @held_results.load tasks.each do |task| held = run_task(task) if held @output.put_hold_notice break end end full_report end
Run a comparison of the entries and puts it on the output.
@return [void]
# File lib/benchmark/memory/job.rb, line 121 def run_comparison if compare? && full_report.comparable? @output.put_comparison(full_report.comparison) end end
Run a task.
@param task [Task]
@return [Boolean] A flag indicating whether to hold or not.
# File lib/benchmark/memory/job.rb, line 98 def run_task(task) if @held_results.include?(task) measurement = @held_results[task.label] full_report.add_entry(task, measurement) return false else measurement = task.call entry = full_report.add_entry(task, measurement) @output.put_entry(entry) if task == tasks.last @held_results.cleanup false else @held_results.add_result(entry) @held_results.holding? end end end