menu_get_object() vs node_load() when getting the node object in Drupal 7

Versions used: 

Sometimes, we need to get node information about the current node we are viewing. In Drupal 6, it was always recommended to use menu_get_object() rather than node_load() to get the node object - the node object has all the information about the node. The reason being that during the inital page request to the node, the node object is cached statically in the function menu_get_item(), a function used by menu_get_object(). So the next time we call menu_get_object(), we are in fact getting a cached version of the node object, making it much faster than node_load().

However, in Drupal 7 this is different, nodes use entities therefore the code in node_load() now also caches the node information. So which one do we use to get information about the current node? Yes, it's test time.

We are going to time how long it takes for node_load() and menu_get_object() to get the node object. To provide a more accurate reading, we will run those functions in a loop 10000 times, then find the average time. Note: I'm using krumo(), and that requires the Devel module.

<?php
 $loop
= 10000;
 
$time = 0;
  for (
$i = 1; $i <= $loop; $i++) {
   
timer_start('menu_get_object');
   
menu_get_object();
   
$time += timer_read('menu_get_object');
  }
 
krumo($time / $loop);
 
 
$time = 0;
  for (
$i = 1; $i <= $loop; $i++) {
   
timer_start('node_load');
   
node_load(arg(1));
   
$time += timer_read('node_load');
  }
 
krumo($time / $loop);
?>

Result:
menu_get_object() = 0.064212 ms
node_load() = 0.057509 ms

So in Drupal 7, node_load() is the preferred function to use as it is slightly quicker in most cases.