Skip to main content
6 events
when toggle format what by license comment
Aug 1, 2013 at 10:42 comment added Reactgular @user1620696 unset only marks data as available for garbage collection, but will not be collected if PHP doesn't need more memory. It's a performance hit to free memory. Only use unset to remote things from arrays or you have logic that tests for variables that are set. With the exception to large chunks of things processed in a loop (like images or datasets). Unset will automatically happen when a variable goes out of scope.
Jul 31, 2013 at 23:54 comment added imel96 @user1620696 I think you should edit your question or post a new more specific one stating what you're trying to achieve. You're already on the right path by profiling how your code run. In this case you show how the script is using memory. If you want speed then don't worry about memory usage, instead, you should just replace your memory_get_usage() with microtime() to measure time. But doing it that way is not very efficient. There are tools like wincachegrind that does better job. Once you know how your script runs, usually you can just take it from there yourself.
Jul 31, 2013 at 22:59 comment added user1620696 @imel96, I've removed the unsets. Can you point me some article that talks more about optimizing for speed and about testing the performance? I've made many changes to my script, removed extra variables, unecessary code and so on, but by this test with memory_get_peak_usage() the impact on performance was very small. Thanks for the help!
Jul 31, 2013 at 22:56 comment added imel96 @user1620696 if you want to optimise for speed, then don't unset(). The garbage collector will do it for you when it needs to or when the script ends. Think memory vs speed trade off.
Jul 31, 2013 at 22:37 comment added user1620696 one doubt yet. I did what you've said and used peak usage instead because of some unsets. The only thing is that using the normal memory_get_usage() the difference between the consumption between the old script and the new was big (25% approximately) while with peak usage the difference is really small (just 2kb). The unsets do not optimze the code then? You know where I can find more about optimizing the speed of the script? Thanks for your help!
Jul 31, 2013 at 21:58 history answered svidgen CC BY-SA 3.0