Sha256: c84af267e4a836cbe4c0aac8cf2cd185516a0812e08d9a0a63c6484bb337b0e6
Contents?: true
Size: 989 Bytes
Versions: 19
Compression:
Stored size: 989 Bytes
Contents
# frozen_string_literal: true require 'benchmark' module PgEventstore # This class measures the performance of Subscription's handler and returns the average time required to process an # event. # @!visibility private class SubscriptionHandlerPerformance extend Forwardable TIMINGS_TO_KEEP = 100 def_delegators :@lock, :synchronize def initialize @lock = Thread::Mutex.new @timings = [] end # Yields the given block to measure its execution time # @return [Object] the result of yielded block def track_exec_time result = nil time = Benchmark.realtime { result = yield } synchronize do @timings.shift if @timings.size == TIMINGS_TO_KEEP @timings.push(time) end result end # The average time required to process an event. # @return [Float] def average_event_processing_time synchronize { @timings.size.zero? ? 0 : @timings.sum / @timings.size } end end end
Version data entries
19 entries across 19 versions & 1 rubygems