Class: SimpleBenchmark
- Inherits:
-
Object
- Object
- SimpleBenchmark
- Defined in:
- lib/simple_benchmark.rb,
lib/simple_benchmark/helper.rb,
lib/simple_benchmark/version.rb
Defined Under Namespace
Modules: Helper
Constant Summary collapse
- VERSION =
"1.0.0"
Class Attribute Summary collapse
-
.enabled ⇒ Object
writeonly
Sets the attribute enabled.
- .logger ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(description, logger = nil) ⇒ SimpleBenchmark
constructor
A new instance of SimpleBenchmark.
- #run(&block) ⇒ Object
Constructor Details
#initialize(description, logger = nil) ⇒ SimpleBenchmark
Returns a new instance of SimpleBenchmark.
23 24 25 26 |
# File 'lib/simple_benchmark.rb', line 23 def initialize(description, logger = nil) @description = description @logger = logger end |
Class Attribute Details
.enabled=(value) ⇒ Object (writeonly)
Sets the attribute enabled
10 11 12 |
# File 'lib/simple_benchmark.rb', line 10 def enabled=(value) @enabled = value end |
.logger ⇒ Object
15 16 17 |
# File 'lib/simple_benchmark.rb', line 15 def self.logger @logger ||= default_logger end |
Class Method Details
.enabled? ⇒ Boolean
19 20 21 |
# File 'lib/simple_benchmark.rb', line 19 def self.enabled? @enabled == true end |
Instance Method Details
#run(&block) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/simple_benchmark.rb', line 28 def run(&block) result = nil report = Benchmark.measure do result = block.call end logger.info("#{@description}: #{report.real} second(s)") result end |