module Utils::IRB::Shell
def irb_time(n = 1, &block)
- Yield: - the block to be executed and timed
Parameters:
-
n
(Integer
) -- the number of times to execute the block, defaults
def irb_time(n = 1, &block) s = Time.now n.times(&block) d = Time.now - s ensure d ||= Time.now - s if n == 1 warn "Took %.3fs seconds." % d else warn "Took %.3fs seconds, %.3fs per call (avg)." % [ d, d / n ] end end