lib/compsci/timer.rb in compsci-0.3.2.3 vs lib/compsci/timer.rb in compsci-0.3.2.4

- old
+ new

@@ -36,11 +36,11 @@ } return val, self.since(start) / i.to_f end # YYYY-MM-DD HH::MM::SS.mmm - def self.timestamp(t) + def self.timestamp(t = Time.now) t.strftime "%Y-%m-%d %H:%M:%S.%L" end # HH::MM::SS.mmm.uuuuuuuu def self.elapsed_display(elapsed_ms, show_us: false) @@ -55,11 +55,11 @@ ms_only.to_s.rjust(3, '0')] hmsms << (ms_fraction * 10 ** 8).round.to_s.ljust(8, '0') if show_us hmsms.join('.') end - def restart(t = Time.now) + def restart(t = Timer.now) @start = t self end alias_method :initialize, :restart @@ -69,28 +69,28 @@ def timestamp!(t = Time.now) puts '-' * 70, timestamp(t), '-' * 70 end - def elapsed(t = Time.now) + def elapsed(t = Timer.now) t - @start end - def elapsed_ms(t = Time.now) + def elapsed_ms(t = Timer.now) elapsed(t) * 1000 end - def elapsed_display(t = Time.now) + def elapsed_display(t = Timer.now) self.class.elapsed_display(elapsed_ms(t)) end alias_method :to_s, :elapsed_display alias_method :inspect, :elapsed_display - def stamp(msg = '', t = Time.now) + def stamp(msg = '', t = Timer.now) format("%s %s", elapsed_display(t), msg) end - def stamp!(msg = '', t = Time.now) + def stamp!(msg = '', t = Timer.now) puts stamp(msg, t) end end end