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! ⇒ 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.
20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#full_report ⇒ Report (readonly)
Returns the full report of all measurements in the job.
30 31 32 |
# File 'lib/benchmark/memory/job.rb', line 30 def full_report @full_report end |
#tasks ⇒ Array<Task> (readonly)
Returns the measurement tasks to run.
33 34 35 |
# File 'lib/benchmark/memory/job.rb', line 33 def tasks @tasks end |
Instance Method Details
#compare! ⇒ void
This method returns an undefined value.
Enable output of a comparison of the different tasks.
47 48 49 |
# File 'lib/benchmark/memory/job.rb', line 47 def compare! @compare = true end |
#compare? ⇒ Boolean
Check whether the job should do a comparison.
40 41 42 |
# File 'lib/benchmark/memory/job.rb', line 40 def compare? @compare end |
#hold!(held_path) ⇒ void
This method returns an undefined value.
Enable holding results to compare between separate runs.
56 57 58 |
# File 'lib/benchmark/memory/job.rb', line 56 def hold!(held_path) @held_results.path = held_path end |
#quiet? ⇒ Boolean
Check whether the job is set to quiet.
130 131 132 |
# File 'lib/benchmark/memory/job.rb', line 130 def quiet? @quiet end |
#report(label = "", &block) ⇒ Object
Add a measurement entry to the job to measure the specified block.
66 67 68 69 70 71 72 |
# 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 ⇒ 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.
121 122 123 124 125 |
# 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_task(task) ⇒ Boolean
Run a task.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# 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 |