Class: SimpleBenchmark

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute enabled to.



10
11
12
# File 'lib/simple_benchmark.rb', line 10

def enabled=(value)
  @enabled = value
end

.loggerObject



15
16
17
# File 'lib/simple_benchmark.rb', line 15

def self.logger
  @logger ||= default_logger
end

Class Method Details

.enabled?Boolean

Returns:

  • (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