Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Magento database collection speed tests
<?php
include_once('app/Mage.php');
Mage::app('default');
function makeWalker($collection, $modelName) {
///echo $collection->getSelect(). "\n";
return array($collection->getSelect()->query(), $modelName);
}
function fetch($walker, $model = null) {
$row = $walker[0]->fetch();
if (!$row) return false;
if (!$model) {
$model = Mage::getModel($walker[1]);
}
$model->setData($row);
return $model;
}
$start = memory_get_usage();
$time_start = microtime(true);
for ($i = 0; $i < 500; ++$i) {
$collection = Mage::getModel('catalog/product')->setStoreId(1)->getCollection()
->addAttributeToSelect('*');
$iterator = makeWalker($collection, 'catalog/product');
$product = null;
while ($product = fetch($iterator, $product)) {
# echo $product->getName() . "\n";
# echo $product->getPrice() . "\n";
}
}
$end = memory_get_usage();
$diff = $end - $start;
echo "$start\n";
echo "$end\n";
echo "$diff\n";
$time_end = microtime(true);
$time_diff = $time_end - $time_start;
echo "$time_diff seconds\n";
<?php
include_once('app/Mage.php');
Mage::app('default');
$start = memory_get_usage();
$time_start = microtime(true);
for ($i = 0; $i < 500; ++$i) {
$collection = Mage::getModel('catalog/product')->setStoreId(1)->getCollection()
->addAttributeToSelect('*');
foreach ($collection as $product) {
# echo $product->getName() . "\n";
# echo $product->getPrice() . "\n";
}
}
$end = memory_get_usage();
$diff = $end - $start;
echo "$start\n";
echo "$end\n";
echo "$diff\n";
$time_end = microtime(true);
$time_diff = $time_end - $time_start;
echo "$time_diff seconds\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.