   show: (type = null) ->
     @reset()
     Xray.isShowing = true
-    bm 'show', =>
+    util.bm 'show', =>
       unless @$overlay.is(':visible')
         $('body').append @$overlay
         @bar.show()

  null

# Scans the document for templates, creating Xray.TemplateSpecimens for them.
Xray.findTemplates = -> bm 'addTemplates', ->
  # Find all <!-- XRAY START ... --> comments
  comments = $('*:not(iframe,script)').contents().filter ->
    this.nodeType == 8 and this.data[0..9] == "XRAY START"

    @$settings.show()


# Utility methods.
util =
  # Computes the bounding box of a jQuery set, which may be many sibling
  # elements with no parent in the set.
  computeBoundingBox: ($contents) ->
    # Edge case: the container may not physically wrap its children, for
    # example if they are floated and no clearfix is present.
    if $contents.length == 1 and $contents.height() <= 0
      return util._computeBoundingBox($contents.children())

    boxFrame =
      top    : Number.POSITIVE_INFINITY
      left   : Number.POSITIVE_INFINITY
      right  : Number.NEGATIVE_INFINITY
      bottom : Number.NEGATIVE_INFINITY

    for el in $contents
      $el = $(el)
      continue unless $el.is(':visible')
      frame = $el.offset()
      frame.right  = frame.left + $el.outerWidth()
      frame.bottom = frame.top + $el.outerHeight()
      boxFrame.top    = frame.top if frame.top < boxFrame.top
      boxFrame.left   = frame.left if frame.left < boxFrame.left
      boxFrame.right  = frame.right if frame.right > boxFrame.right
      boxFrame.bottom = frame.bottom if frame.bottom > boxFrame.bottom

    return {
      left   : boxFrame.left
      top    : boxFrame.top
      width  : boxFrame.right - boxFrame.left
      height : boxFrame.bottom - boxFrame.top
    }

  # Benchmark a piece of code
  bm: (name, fn) ->
    time = new Date
    result = fn()
    # console.log "#{name} : #{new Date() - time}ms"
    result
