Module: Kernel

Defined in:
lib/fat_core/kernel.rb

Instance Method Summary collapse

Instance Method Details

#time_it(name = 'block', &block) ⇒ Object

Run the given block and report the time it took to execute in hour-minute-second form.

Examples:

result = time_it 'Fibbonacci' do
  Fibbonacci.fib(30)
end
puts "For 30 its #{result}"
=> "Ran Fibonacci in 30:23"

Parameters:

  • name (String, #to_s) (defaults to: 'block')

    an optional name to use for block in timing message.

Returns:

  • (Object)

    whatever the block returns


17
18
19
20
21
22
23
# File 'lib/fat_core/kernel.rb', line 17

def time_it(name = 'block', &block)
  start = Time.now
  result = yield block
  run_time = Time.now - start
  puts "Ran #{name} in #{run_time.secs_to_hms}"
  result
end