Bit different numbers here. "xhprof'ed" with with ~700 products ....
$storeId = 1;
$productIds = Mage::getModel('catalog/category')->load(41)
->getProductCollection()
->getAllIds();
Xhprof_Profiler::start();
# ...
var_dump($weight);
Xhprof_Profiler::stop();
1) getAttributeRawValue()
$rm = Mage::getResourceModel('catalog/product');
foreach ($productIds as $productId) {
$weight[$productId] = $rm->getAttributeRawValue($productId, 'weight', $storeId);
}
- Total Incl. Wall Time (microsec): 5,572,944 microsecs
- Total Incl. CPU (microsecs): 5,425,659 microsecs
- Total Incl. MemUse (bytes): 1,302,512 bytes
- Total Incl. PeakMemUse (bytes): 1,272,360 bytes
- Number of Function Calls: 254,235
2) Mage::getModel('catalog/product')->getCollection()
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('weight')
->addAttributeToFilter('entity_id', $productIds);
foreach ($collection as $product) {
$weight[$product->getId()] = $product->getWeight();
}
- Total Incl. Wall Time (microsec): 2,588,250 microsecs
- Total Incl. CPU (microsecs): 2,549,021 microsecs
- Total Incl. MemUse (bytes): 3,717,824 bytes
- Total Incl. PeakMemUse (bytes): 3,834,616 bytes
- Number of Function Calls: 124,602
3) Mage::getResourceModel('catalog/product_collection')
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('weight')
->addAttributeToFilter('entity_id', $productIds);
foreach ($collection as $product) {
$weight[$product->getId()] = $product->getWeight();
}
- Total Incl. Wall Time (microsec): 2,603,804 microsecs
- Total Incl. CPU (microsecs): 2,584,472 microsecs
- Total Incl. MemUse (bytes): 3,706,600 bytes
- Total Incl. PeakMemUse (bytes): 3,821,336 bytes
- Number of Function Calls: 124,554
5) using addIdFilter()
*
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('weight')
->addIdFilter($productIds);
foreach ($collection as $product) {
$weight[$product->getId()] = $product->getWeight();
}
- Total Incl. Wall Time (microsec): 2,439,878 microsecs
- Total Incl. CPU (microsecs): 2,419,062 microsecs
- Total Incl. MemUse (bytes): 3,689,440 bytes
- Total Incl. PeakMemUse (bytes): 3,700,200 bytes
- Number of Function Calls: 118,409
6) using getColumnValues()
*
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('weight')
->addIdFilter($productIds);
$weight = array_combine(
$collection->getColumnValues('entity_id'),
$collection->getColumnValues('weight')
);
- Total Incl. Wall Time (microsec): 2,140,222 microsecs
- Total Incl. CPU (microsecs): 2,119,635 microsecs
- Total Incl. MemUse (bytes): 3,180,560 bytes
- Total Incl. PeakMemUse (bytes): 3,260,200 bytes
- Number of Function Calls: 104,722
* nearly same result for 'entity_id', array('in' => $productIds)
, but it's less to type and better readable