You are here

static function crumbs_Util::benchmark in Crumbs, the Breadcrumbs suite 7.2

Measures time between two runs and displays it in a human-readable format.

Parameters

$label: String used to identify the measured time.

Return value

null|string A string with the measurement, or NULL if the function was run for the first time.

File

lib/Util.php, line 82

Class

crumbs_Util
Static methods that don't fit elsewhere. Ideally these are all stateless and do not depend on anything. But at least one of them is not..

Code

static function benchmark($label = NULL) {
  static $previous_time;
  $current_time = microtime(TRUE);
  if (isset($previous_time) && isset($label)) {
    $str = 'Duration: ' . number_format(1000 * ($current_time - $previous_time), 3) . ' ms for ' . $label;
  }
  $previous_time = $current_time;
  return isset($str) ? $str : NULL;
}