Task: load title of node
Count: 1'000 (nodes)
The measurement happens on a (close to) clean Drupal 7.34 install. Each iteration started with a clear cache - which can be observed where caching is available and first call is much worse. There are 10 different scenarios:
Note: means and medians are only for times, as memory consumptions are constant through iterations.
$var = db_query("
SELECT title
FROM {node}
")->fetchCol();
$vars = array();
for ($i = 1; $i <= 1000; $i++) {
$vars[] = db_query("
SELECT title
FROM {node}
WHERE nid = :nid
", array(':nid' => $i))->fetchField();
}
$var = db_select('node', 'n')->fields('n', array('title'))->execute()->fetchCol();
$vars = array();
for ($i = 1; $i <= 1000; $i++) {
$vars[] = db_select('node', 'n')->fields('n', array('title'))->condition('nid', $i)->execute()->fetchField();
}
$nodes = node_load_multiple(range(1, 1000, 1));
$vars = array();
foreach ($nodes as $node) {
$vars[] = $node->title;
}
$nodes = entity_load('node', range(1, 1000, 1));
$vars = array();
foreach ($nodes as $node) {
$vars[] = $node->title;
}
$vars = array();
for ($i = 1; $i <= 1000; $i++) {
$node = node_load($i);
$vars[] = $node->title;
}
$vars = array();
for ($i = 1; $i <= 1000; $i++) {
$node = node_load($i);
$entity = entity_metadata_wrapper('node', $node);
$vars[] = $entity->title->value();
}
$f = cw_tool_get_container()->get('node.controller.factory');
$vars = array();
for ($i = 1; $i <= 1000; $i++) {
$n = $f->initWithId($i);
$vars[] = $n->data()->title;
}