Class: Airbrake::Benchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake-ruby/benchmark.rb

Overview

Benchmark benchmarks Ruby code.

Since:

  • v4.2.4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBenchmark

Returns a new instance of Benchmark.

Since:

  • v4.3.0



23
24
25
26
# File 'lib/airbrake-ruby/benchmark.rb', line 23

def initialize
  @start = MonotonicTime.time_in_ms
  @duration = 0.0
end

Instance Attribute Details

#durationFloat (readonly)

Returns:

  • (Float)

Since:

  • v4.2.4



20
21
22
# File 'lib/airbrake-ruby/benchmark.rb', line 20

def duration
  @duration
end

Class Method Details

.measureObject

Measures monotonic time for the given operation.

Yield Returns:

  • (void)

Since:

  • v4.2.4



10
11
12
13
14
15
16
17
# File 'lib/airbrake-ruby/benchmark.rb', line 10

def self.measure
  benchmark = new

  yield

  benchmark.stop
  benchmark.duration
end

Instance Method Details

#stopBoolean

Stops the benchmark and stores ‘duration`.

Returns:

  • (Boolean)

    true for the first invocation, false in all other cases

Since:

  • v4.3.0



32
33
34
35
36
37
# File 'lib/airbrake-ruby/benchmark.rb', line 32

def stop
  return false if @duration > 0.0

  @duration = MonotonicTime.time_in_ms - @start
  true
end