Sha256: 6130e00c6c79e220c1513f3906d3ca9c95f36001ca4fff39d114da1a34c73124
Contents?: true
Size: 666 Bytes
Versions: 1
Compression:
Stored size: 666 Bytes
Contents
# frozen_string_literal: true class Quickdraw::Timer class Duration def initialize(duration) @duration = duration end def to_s if @duration < 1_000 "#{@duration}ns" elsif @duration < 1_000_000 "#{@duration / 1_000}μs" elsif @duration < 1_000_000_000 "#{@duration / 1_000_000}ms" elsif @duration < 60_000_000_000 "#{@duration / 1_000_000_000}s" else "#{(@duration / 60_000_000_000)}m" end end end def self.time start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) yield finish = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) Duration.new(finish - start) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
quickdraw-0.1.0 | lib/quickdraw/timer.rb |