Module: Morpheus::Benchmarking::HasBenchmarking
- Included in:
- Terminal
- Defined in:
- lib/morpheus/benchmarking.rb
Overview
Mixin for any class that needs benchmarking
Instance Method Summary collapse
- #start_benchmark(opts) ⇒ Object
-
#stop_benchmark(exit_code = 0, err = nil) ⇒ Object
finish the current benchmark and optionally print the time taken.
-
#with_benchmark(opts, &block) ⇒ Object
def benchmark_record @benchmark_record end.
Instance Method Details
#start_benchmark(opts) ⇒ Object
141 142 143 144 |
# File 'lib/morpheus/benchmarking.rb', line 141 def start_benchmark(opts) @benchmark_record = BenchmarkRecord.new(opts) return @benchmark_record end |
#stop_benchmark(exit_code = 0, err = nil) ⇒ Object
finish the current benchmark and optionally print the time taken.
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/morpheus/benchmarking.rb', line 147 def stop_benchmark(exit_code=0, err=nil) if defined?(@benchmark_record) && @benchmark_record @benchmark_record.stop(exit_code, err) @last_benchmark_record = @benchmark_record @benchmark_record = nil return @last_benchmark_record else return nil end end |
#with_benchmark(opts, &block) ⇒ Object
def benchmark_record
@benchmark_record
end
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/morpheus/benchmarking.rb', line 122 def with_benchmark(opts, &block) exit_code, err = 0, nil begin start_benchmark(opts) if block_given? result = block.call() exit_code, err = Morpheus::Cli::CliRegistry.parse_command_result(result) end rescue => ex raise ex exit_code = 1 err = ex.msg ensure stop_benchmark(exit_code, err) end #return result return exit_code, err end |