You are here

function _views_bulk_operations_timer in Views Bulk Operations (VBO) 8.2

Same name and namespace in other branches
  1. 8.3 views_bulk_operations.drush.inc \_views_bulk_operations_timer()
  2. 4.0.x views_bulk_operations.drush.inc \_views_bulk_operations_timer()

Helper function to set / get timer.

Parameters

bool $debug: Should the function do anything at all?

string $id: ID of a specific timer span.

Return value

mixed NULL or value of a specific timer if set.

1 call to _views_bulk_operations_timer()
drush_views_bulk_operations_execute in ./views_bulk_operations.drush.inc
The vbo-exec command executtion function.

File

./views_bulk_operations.drush.inc, line 51
Contains code providing drush commands functionality.

Code

function _views_bulk_operations_timer($debug = TRUE, $id = NULL) {
  if (!$debug) {
    return;
  }
  static $timers = [];
  if (!isset($id)) {
    $timers['start'] = microtime(TRUE);
  }
  else {
    if (isset($timers[$id])) {
      end($timers);
      do {
        if (key($timers) === $id) {
          return round((current($timers) - prev($timers)) * 1000, 3);
        }
        else {
          $result = prev($timers);
        }
      } while ($result);
    }
    else {
      $timers[$id] = microtime(TRUE);
    }
  }
}