Sha256: 0985c2b48c303a87dcdd1ba7b3567f1f1229b4e44d6db0f78b226a418e4b3077
Contents?: true
Size: 827 Bytes
Versions: 12
Compression:
Stored size: 827 Bytes
Contents
module Rex::Stopwatch # This provides a correct way to time an operation provided within a block. # # @see https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/ # @see https://ruby-doc.org/core-2.7.1/Process.html#method-c-clock_gettime # # @param [Symbol] unit The unit of time in which to measure the duration. The # argument is passed to Process.clock_gettime which defines the acceptable # values. # # @yield [] The block whose operation should be timed. # # @return Returns the result of the block and the elapsed time in the specified unit. def self.elapsed_time(unit: :float_second) start = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) ret = yield elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) - start [ret, elapsed] end end
Version data entries
12 entries across 12 versions & 1 rubygems