Re: Re: Memory investigation

From: Date: Wed, 03 Mar 2010 20:29:26 +0000
Subject: Re: Re: Memory investigation
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-302525@lists.php.net to get a copy of this message
couple questions Larry is this application composed of classes or straight up no holes barred procedural code? larry@garfieldtech.com wrote:
That's not really what I'm after. Let me try an example: function foo($id) { static $foos = array(); if (empty($foos[$id]) {
    $foos[$id] = load_foo($id);
} return $foos[$id]; } When load_foo() is slow (e.g., lots of DB traffic or remote-server calls or whatever), such caching can have a significant performance boost. Sometime after foo() has been called 15 times from 30 places in code, when I get to the end of the request (or just every time I call foo() would be fine) I want to be able to do something like: $cost = get_memory_used_by($foos); So that I can determine how much memory that caching is costing me over the lifetime of the page, and determine if it's a worthwhile trade-off. --Larry Garfield dsiembab01@gmail.com wrote:
function check_memory_usage(&$memory) {
    $memory[] = memory_get_usage();
    return $memory;
} something like this? you can put it wherever you like and returns an array for further processing. You could optionally add a second argument to set the index to a name and check if the name exists to add 1 to the end of the name so your indexes stay maintained.


« previous php.general (#302525) next »