-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel-load-in-loop.php
56 lines (49 loc) · 1.53 KB
/
model-load-in-loop.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
ini_set('memory_limit', '512M');
$getProductIds = function ($number) {
$productIds = array();
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getSelect()->limit($number);
foreach ($collection as $product) {
$productIds[] = $product->getId();
}
$collection->clear();
return $productIds;
};
$exp1 = function ($productIds) {
$start = microtime(true);
$r = array();
$collection = Mage::getResourceModel('catalog/product_collection')
->addFieldToFilter('entity_id', array($productIds))
->addAttributeToSelect(array('name'));
foreach ($collection as $product) {
$r[] = $product->getName();
}
$end = microtime(true);
$collection->clear();
return $end - $start;
};
$exp2 = function ($productIds) {
$start = microtime(true);
$r = array();
foreach ($productIds as $productId) {
$product = Mage::getModel('catalog/product')->load($productId);
$r[] = $product->getName();
}
$end = microtime(true);
return $end - $start;
};
echo '<table><tr><td># of Products</td><td>Collection</td><td>Model Loop</td></tr>';
for ($i = 10; $i <= 1000; $i = $i + 20) {
if ($i != 10) $n = $i - 10; else $n = $i;
$start = microtime(true);
$productIds = $getProductIds($n);
$end = microtime(true);
echo '<tr>';
echo '<td>' . $n . '</td>';
echo '<td>' . ($exp1($productIds) + ($end - $start)) . '</td>';
echo '<td>' . $exp2($productIds) . '</td>';
echo '</tr>';
}
echo '</table>';
die();