Last active
August 17, 2016 11:54
-
-
Save avoelkl/660cae48ef87e3f133ccbc587c4fa342 to your computer and use it in GitHub Desktop.
Testing efficient way of loading customer data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once '../app/Mage.php'; | |
Mage::app(); | |
umask(0); | |
$customerId = 575420; | |
$start = microtime(); | |
$memory1 = memory_get_usage(); | |
$customer = Mage::getModel('customer/customer')->load($customerId); | |
$firstname = $customer->getFirstname(); | |
$lastname = $customer->getLastname(); | |
$memory2 = memory_get_usage(); | |
$end = microtime(); | |
echo "<p>"; | |
echo $firstname . "<br />"; | |
echo $lastname . "<br />"; | |
echo "Start: $start, End: $end => " . ($end - $start) . "<br />"; | |
echo "Memory Start: $memory1, End: $memory2 => " . ($memory2 - $memory1)/1024 . "KB <br />"; | |
echo "</p><p>"; | |
$start = microtime(); | |
$memory3 = memory_get_usage(); | |
$customer = Mage::getModel('customer/customer') | |
->getCollection() | |
->addAttributeToSelect('firstname') | |
->addAttributeToSelect('lastname') | |
->addAttributeToFilter('entity_id', $customerId) | |
->getFirstItem(); | |
$firstname = $customer->getFirstname(); | |
$lastname = $customer->getLastname(); | |
$memory4 = memory_get_usage(); | |
$end = microtime(); | |
echo "<p>"; | |
echo $firstname . "<br />"; | |
echo $lastname . "<br />"; | |
echo "Start: $start, End: $end => " . ($end - $start) . "<br />"; | |
echo "Memory Start: $memory3, End: $memory4 => " . ($memory4 - $memory3)/1024 . " KB<br />"; | |
echo "</p>"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First call:
Time: 0.018482
Memory: 1875.171875KB
Second call:
Time: 0.001501
Memory: 122.3671875 KB