Page 1 of 1

Memory usage of a part of the script

Posted: Tue Jan 27, 2009 5:08 am
by vileda
I am trying to do a small memory usage test on two different web applications. The problem is, that I haven't found any methods to calculate the mamximum memory usage for only a part of the script. The PHP function memory_get_peak_usage returns the peak usage of the whole script, and the peak usage is reached already at the beginning of the script.

Below is a short description about the scripts.

Code: Select all

<?php
    // Some code, which shouldn't affect to the test
    include_once('included_file.php');
    // Some more code, which shouldn't affect to the test
?>
The included_file.php:

Code: Select all

<?php
    // Some more code, which shouldn't affect to the test
 
    // *** The test starts here. ***
    $initial_memory = memory_get_usage();
    //
    // Here comes the part of the script, 
    // which peak memory usage I want to test!
    //
    $end_memory = memory_get_usage();
    $peak_memory = mystery_to_me( ';)' );
    // *** The test ends here. ***
 
    // Some more code...
?>
I am using Apache/2.2.8 (Win32) PHP/5.2.6 on Windows XP.

Is there any possibilities to get what I need?

Thanks!

Re: Memory usage of a part of the script

Posted: Tue Jan 27, 2009 5:45 am
by Chris Corbyn
Use XDebug and do some proper profiling of the code.