class MultimediaParadise::Waveform::Log

Attributes

io[RW]

Public Class Methods

new(io = $stdout) click to toggle source
#

initialize

#
# File lib/multimedia_paradise/audio/waveform/log.rb, line 27
def initialize(io = $stdout)
  @io = io
end

Public Instance Methods

done!(message = '') click to toggle source
#

done!

Prints the given message to the log followed by the most recent benchmark (note that it calls .end! which will stop the benchmark)

#
# File lib/multimedia_paradise/audio/waveform/log.rb, line 46
def done!(message = '')
  out "#{message} (#{self.end!}s)\n"
end
end!() click to toggle source
#

end!

Returns the elapsed time from the most recently started benchmark clock and ends the benchmark, so that a subsequent call to .end! will return the elapsed time from the previously started benchmark clock.

#
# File lib/multimedia_paradise/audio/waveform/log.rb, line 72
def end!
  elapsed = (Time.now - @benchmarks[@current])
  @current -= 1
  elapsed
end
out(i) click to toggle source
#

out

Prints the given message to the log.

#
# File lib/multimedia_paradise/audio/waveform/log.rb, line 36
def out(i)
  io.print(i) if io
end
start!() click to toggle source
#

start!

Starts a new benchmark clock and returns the index of the new clock.

If .start! is called again before .end! then the time returned will be the elapsed time from the next call to start!, and calling .end! again will return the time from this call to start! (that is, the clocks are LIFO).

#
# File lib/multimedia_paradise/audio/waveform/log.rb, line 60
def start!
  (@benchmarks ||= []) << Time.now
  @current = @benchmarks.size - 1
end
time?(index) click to toggle source
#

time?

Returns the elapsed time from the benchmark clock w/ the given index (as returned from when .start! was called).

#
# File lib/multimedia_paradise/audio/waveform/log.rb, line 84
def time?(index)
  Time.now - @benchmarks[index]
end
timed(message = nil) { || ... } click to toggle source
#

timed

Benchmarks the given block, printing out the given message first (if given).

#
# File lib/multimedia_paradise/audio/waveform/log.rb, line 94
def timed(message = nil, &block)
  start!
  out(message) if message
  yield
  done!
end