XML memory consumption test example one
To run this script on your environment you need PHP installed. I prefer to run this script in terminal (php-cli).
To see *actual* memory usage of this script run the following command in terminal: top -b -d .001 | grep php . Once above command is running, execute the following php script using command: php stats.php (assuming you've saved this file on your own computer with file name "stats.php").
REQUIREMENT:
To get meaningful results from this test script you must obtain/prepare plain text XML files and save them in the same directory as this php script. Ideally your XML files will be at least several MB in size to make memory reporting discrepancy more apparent.
I've named my test XML files file1.xml through file4.xml. you may have different file names in which case you must modify the $files array to represent your environment accurately.
<?php
function convert($size) {
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
// Respective filesizes noted. Comment out individual file names as appropriate to fit your environment.
$files = array(
'file1.xml', // 46MB file size on my environment. In your tests
'file2.xml', // 11MB file sizes maybe different, which is all right.
'file3.xml', // 4.5MB
'file4.xml', // 7.6MB
);
foreach ($files as $file) {
print $file . "\n";
$xml[] = new SimpleXMLElement($file, 0, TRUE);
}
/* Figures reported during my test were as follows (consistent between multiple runs)
Array
(
[mem] => 625.51 kb
[mem_real] => 768 kb
[max] => 635.52 kb
[max_real] => 768 kb
)
// As you will undoubtedly find out shortly, these figures are absolutely wrong.
*/
$stats = array(
'mem' => convert(memory_get_usage()),
'mem_real' => convert(memory_get_usage(TRUE)),
'max' => convert(memory_get_peak_usage()),
'max_real' => convert(memory_get_peak_usage(TRUE)),
);
print_r($stats);
sleep(1);
No responses to "XML memory consumption test example one"
Post new comment