alienblocktimer.rb

Path: alienblocktimer.rb
Last Update: Fri Jun 13 11:38:04 -0700 2014

Alien Ruby RFID Library

alienblocktimer.rb

A tiny little class to help me time code blocks. Ruby has a ‘profiler’ library that is much more powerful, but I‘ve found this handy for quick timing checks.

Returns elapsed time for an operation and an optional description.

Example 1):

  You can just create the timer in place and use it.

  puts AlienBlockTimer.new("Time for this block: "){
    ... Some lengthy operation in the block ...
  }

  Results in:

  Time for this block: 0.123

Example 2):

  Alternatively, create an instance and use it later.

  t=AlienBlockTimer.new("")

  puts t.measure("Time for this block: "){
    ... Some lengthy operation in the block ...
  }

  ...or...

  t.measure("Time for this other block: "){
  ... Some lengthy operation in the block ...
  }

  puts t

Example 3):

  You can also use the class to make a series of elapsed time measurements.

  puts "Starting measurment..."

  t.start

  (code here...)

  puts "So far: #{t.elapsed}"

  (more code...)

  puts "Done!: #{t.elapsed}"

Copyright 2007 Alien Technology Corporation. All rights reserved.

[Validate]