"a more efficient way" is to use product collcections where final price addis already add to. Some numbers here: What is faster - getting raw attribute value or use collection?
Using ->addFinalPrice()
will add something like this to collection query ...
,
price_index
.price
,price_index
.tax_class_id
,price_index
.final_price
, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) ASminimal_price
,price_index
.min_price
,price_index
.max_price
,price_index
.tier_price
and
INNER JOIN
catalog_product_index_price
ASprice_index
ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
I'd us a colletion like
$collection = Mage::getResourceModel('catalog/product_collection')
->addIdFilter($productIds)
->addFinalPrice();
foreach ($collection as $product) {
$finalPrices[] = $product->getFinalPrice();
}
- Total Incl. Wall Time (microsec): 2,131,092 microsecs
- Total Incl. CPU (microsecs): 2,109,925 microsecs
- Total Incl. MemUse (bytes): 4,776,976 bytes
- Total Incl. PeakMemUse (bytes): 4,829,112 bytes
- Number of Function Calls: 103,275
compared to
foreach($productIds as $productId) {
$finalPrices[] = Mage::getModel('catalog/product')->load($productId)->getFinalPrice();
}
- Total Incl. Wall Time (microsec): 116,555,318 microsecs
- Total Incl. CPU (microsecs): 114,323,845 microsecs
- Total Incl. MemUse (bytes): 22,853,768 bytes
- Total Incl. PeakMemUse (bytes): 23,126,448 bytes
- Number of Function Calls: 5,465,676