@ 2013-08-07T22:55:28Z <?php
class VarStorage
{
protected $_property;
public function setProperty($value)
{
$this->_property = $value;
}
public function getProperty()
{
return $this->_property;
}
}
function mem_print($message, $before, $after) {
$difference = ($after - $before) / 1000000;
echo sprintf($message, sprintf('%.2fM', $difference));
echo "\n";
}
echo "Testing class in a PHP script\n\n";
// Create massive variable
$mBeforeA = memory_get_usage();
$a1 = str_repeat('a', 3000000);
$mAfterA = memory_get_usage();
mem_print('Creating $a1: %s', $mBeforeA, $mAfterA);
// Refcount increases
$a2 = str_repeat('a', 3000000);
$mBeforeB = memory_get_usage();
$b = $a2;
$mAfterB = memory_get_usage();
mem_print('$b = $a2: %s', $mBeforeB, $mAfterB);
// Separation
$mBeforeSeparation = memory_get_usage();
$b .= '';
$mAfterSeparation = memory_get_usage();
mem_print('$b .= '': %s', $mBeforeSeparation, $mAfterSeparation);
// Setting to a class property
$a4 = str_repeat('a', 3000000);
$class = new VarStorage;
$mBeforeStorageSet = memory_get_usage();
$class->setProperty($a4);
$mAfterStorageSet = memory_get_usage();
mem_print('$class->setProperty($a4): %s', $mBeforeStorageSet, $mAfterStorageSet);
// Getting from a class property
$mBeforeStorageGet = memory_get_usage();
$result = $class->getProperty();
$mAfterStorageGet = memory_get_usage();
mem_print('$result = $class->getProperty(): %s', $mBeforeStorageGet, $mAfterStorageGet);
$mBeforeSeparationFromStorage = memory_get_usage();
$result .= '';
$mAfterSeparationFromStorage = memory_get_usage();
mem_print('$result .= \'\': %s', $mBeforeSeparationFromStorage, $mAfterSeparationFromStorage);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.17 0.029 0.079 12.40 5.4.16 0.015 0.047 12.39 5.4.15 0.020 0.043 12.39 5.4.14 0.021 0.069 12.08 5.4.13 0.019 0.043 12.06 5.4.12 0.019 0.041 12.03 5.4.11 0.016 0.043 12.02 5.4.10 0.026 0.063 12.03 5.4.9 0.015 0.043 12.03 5.4.8 0.021 0.067 12.02 5.4.7 0.014 0.043 12.02 5.4.6 0.019 0.038 12.02 5.4.5 0.010 0.047 12.02 5.4.4 0.014 0.043 12.00 5.4.3 0.020 0.070 12.00 5.4.2 0.016 0.042 12.00 5.4.1 0.011 0.046 12.00 5.4.0 0.015 0.042 11.49 5.3.27 0.017 0.045 12.72 5.3.26 0.018 0.043 12.72 5.3.25 0.017 0.042 12.72 5.3.24 0.019 0.041 12.72 5.3.23 0.016 0.046 12.71 5.3.22 0.016 0.044 12.68 5.3.21 0.014 0.047 12.68 5.3.20 0.016 0.045 12.68 5.3.19 0.015 0.064 12.67 5.3.18 0.018 0.042 12.67 5.3.17 0.014 0.046 12.67 5.3.16 0.013 0.046 12.67 5.3.15 0.018 0.041 12.67 5.3.14 0.019 0.041 12.66 5.3.13 0.024 0.067 12.66 5.3.12 0.017 0.043 12.66 5.3.11 0.015 0.045 12.66 5.3.10 0.016 0.044 12.13 5.3.9 0.015 0.043 12.11 5.3.8 0.019 0.056 12.09 5.3.7 0.013 0.045 12.09 5.3.6 0.015 0.044 12.08 5.3.5 0.015 0.043 12.02 5.3.4 0.019 0.054 12.03 5.3.3 0.015 0.041 11.99 5.3.2 0.016 0.042 11.77 5.3.1 0.017 0.053 11.75 5.3.0 0.014 0.043 11.72
preferences:dark mode live preview
142.98 ms | 1386 KiB | 7 Q