Fork me on GitHub

Timing Drupal Module Loading

When tweaking a Drupal install module overhead is something to take into consideration. Below is a modifcation to the Drupal 4.7 drupal_load function (which exists in includes/bootstrap.inc) that puts module load time into a global array:
function drupal_load($type, $name) {
  static $files = array();
  if (isset($files[$type][$name])) {
    return TRUE;
  }
 
  $filename = drupal_get_filename($type, $name);
 
  if ($filename) {
 
    if ($type == 'module') {
      timer_start('time_' . $name);
    }
    include_once "./$filename";
    if ($type == 'module') {
      $module_load_time = timer_read('time_' . $name);
      $GLOBALS['module_timers']['total'] = 
        $GLOBALS['module_timers']['total'] + $module_load_time;
      $GLOBALS['module_timers'][$name] = $module_load_time;
    }
    $files[$type][$name] = TRUE;
 
    return TRUE;
  }
 
  return FALSE;
}
To display the timing information in an HTML comment, add this code to the end of your index.php file:
print "<!-- ";
arsort($GLOBALS['module_timers']);
print_r($GLOBALS['module_timers']);
print "-->";