Class: Benchmark::Memory::Job
- Inherits:
-
Object
- Object
- Benchmark::Memory::Job
- Extended by:
- Forwardable
- Defined in:
- lib/benchmark/memory/job.rb,
lib/benchmark/memory/job/task.rb,
lib/benchmark/memory/job/io_output.rb,
lib/benchmark/memory/job/null_output.rb,
lib/benchmark/memory/job/io_output/entry_formatter.rb,
lib/benchmark/memory/job/io_output/metric_formatter.rb,
lib/benchmark/memory/job/io_output/comparison_formatter.rb
Overview
Encapsulate the memory measurements of reports.
Defined Under Namespace
Classes: IOOutput, NullOutput, Task
Instance Attribute Summary collapse
-
#full_report ⇒ Report
readonly
The full report of all measurements in the job.
-
#tasks ⇒ Array<Task>
readonly
The measurement tasks to run.
Instance Method Summary collapse
-
#compare!(**spec) ⇒ void
Enable output of a comparison of the different tasks.
-
#compare? ⇒ Boolean
Check whether the job should do a comparison.
-
#hold!(held_path) ⇒ void
Enable holding results to compare between separate runs.
-
#initialize(output: $stdout, quiet: false) ⇒ Job
constructor
Instantiate a job for containing memory performance reports.
-
#quiet? ⇒ Boolean
Check whether the job is set to quiet.
-
#report(label = '', &block) ⇒ Object
Add a measurement entry to the job to measure the specified block.
-
#run ⇒ Report
Run the job and outputs its full report.
-
#run_comparison ⇒ void
Run a comparison of the entries and puts it on the output.
-
#run_task(task) ⇒ Boolean
Run a task.
Constructor Details
#initialize(output: $stdout, quiet: false) ⇒ Job
Instantiate a job for containing memory performance reports.
23 24 25 26 27 28 29 |
# File 'lib/benchmark/memory/job.rb', line 23 def initialize(output: $stdout, quiet: false) @full_report = Report.new @held_results = HeldResults.new @quiet = quiet @output = quiet? ? NullOutput.new : IOOutput.new(output) @tasks = [] end |
Instance Attribute Details
#full_report ⇒ Report (readonly)
Returns the full report of all measurements in the job.
32 33 34 |
# File 'lib/benchmark/memory/job.rb', line 32 def full_report @full_report end |
#tasks ⇒ Array<Task> (readonly)
Returns the measurement tasks to run.
35 36 37 |
# File 'lib/benchmark/memory/job.rb', line 35 def tasks @tasks end |
Instance Method Details
#compare!(**spec) ⇒ void
This method returns an undefined value.
Enable output of a comparison of the different tasks.
49 50 51 |
# File 'lib/benchmark/memory/job.rb', line 49 def compare!(**spec) @comparator = full_report.comparator = Report::Comparator.from_spec(spec.to_h) end |
#compare? ⇒ Boolean
Check whether the job should do a comparison.
42 43 44 |
# File 'lib/benchmark/memory/job.rb', line 42 def compare? !!@comparator end |
#hold!(held_path) ⇒ void
This method returns an undefined value.
Enable holding results to compare between separate runs.
58 59 60 |
# File 'lib/benchmark/memory/job.rb', line 58 def hold!(held_path) @held_results.path = held_path end |
#quiet? ⇒ Boolean
Check whether the job is set to quiet.
118 119 120 |
# File 'lib/benchmark/memory/job.rb', line 118 def quiet? @quiet end |
#report(label = '', &block) ⇒ Object
Add a measurement entry to the job to measure the specified block.
68 69 70 71 72 |
# File 'lib/benchmark/memory/job.rb', line 68 def report(label = '', &block) raise ArgumentError, 'You did not specify a block for the item' unless block_given? tasks.push Task.new(label, block) end |
#run ⇒ Report
Run the job and outputs its full report.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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_comparison ⇒ void
This method returns an undefined value.
Run a comparison of the entries and puts it on the output.
109 110 111 112 113 |
# File 'lib/benchmark/memory/job.rb', line 109 def run_comparison return unless compare? && full_report.comparable? @output.put_comparison(full_report.comparison) end |
#run_task(task) ⇒ Boolean
Run a task.
98 99 100 101 102 103 104 |
# File 'lib/benchmark/memory/job.rb', line 98 def run_task(task) if @held_results.include?(task) run_with_held_results(task) else run_without_held_results(task) end end |