You are here

protected function ViewsBulkOperationsCommands::timer in Views Bulk Operations (VBO) 8.3

Same name and namespace in other branches
  1. 8.2 src/Commands/ViewsBulkOperationsCommands.php \Drupal\views_bulk_operations\Commands\ViewsBulkOperationsCommands::timer()
  2. 4.0.x src/Commands/ViewsBulkOperationsCommands.php \Drupal\views_bulk_operations\Commands\ViewsBulkOperationsCommands::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 ViewsBulkOperationsCommands::timer()
ViewsBulkOperationsCommands::vboExecute in src/Commands/ViewsBulkOperationsCommands.php
Execute an action on all results of the specified view.

File

src/Commands/ViewsBulkOperationsCommands.php, line 247

Class

ViewsBulkOperationsCommands
Defines Drush commands for the module.

Namespace

Drupal\views_bulk_operations\Commands

Code

protected function 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);
    }
  }
}