Skip to content

Instantly share code, notes, and snippets.

@salamoun
Created September 8, 2015 14:05
Show Gist options
  • Save salamoun/fdfd2a595334e88c6fb7 to your computer and use it in GitHub Desktop.
Save salamoun/fdfd2a595334e88c6fb7 to your computer and use it in GitHub Desktop.
<?
ini_set("memory_limit","1500K");
echo 'php: ' . phpversion() . '<br/>';
echo 'usage: ' . round(($bef = memory_get_usage(false)) / 1024, 1) . ' kB (int size: ' . PHP_INT_SIZE . ')<br/>';
$tm = microtime(true);
class smt {
private $a;
private $b;
private $c;
public function __construct($a, $b, $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
public function get_sum() { return $this->a + $this->b + $this->c; }
}
gc_disable();
for ($i=0; $i<10; $i++) {
echo '=== ITERACE '.$i.'===<br/>';
$data = array();
for ($sf = 0; $sf < 1000; $sf++) {
$data[] = array(
'value_1' => (int)rand(),
'value_2' => (int)rand(),
'value_3' => (int)rand(),
'value_4' => (int)rand()
//'ref' => new smt(rand(), rand(), rand())
);
}
echo 'usage_'.$i.': ' . round(($t = memory_get_usage(false)) / 1024, 1) . ' kB (diff ' . round(($t - $bef) / 1024, 1) . ' kB ~ ' . ($t - $bef) . ' B)<br/>';
echo 'time_'.$i.': ' . round((microtime(true) - $tm), 2) . ' sec<br/>';
$top = $sf = $a = $sum1 = $b = $sum2 = $tt = null;
$data = NULL;
unset($data);
echo 'usage after unset_'.$i.' - emalloc: ' . round(($t = memory_get_usage(false)) / 1024, 1) . ' kB<br/>';
echo 'usage after unset_'.$i.' - real: ' . round(($t = memory_get_usage(true)) / 1024, 1) . ' kB<br/>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment