Script Speed vs Memory Usage

Posted by Doug Neiner on Stack Overflow See other posts from Stack Overflow or by Doug Neiner
Published on 2010-03-20T05:38:54Z Indexed on 2010/03/20 5:41 UTC
Read the original article Hit count: 249

Filed under:
|
|
|

I am working on an image generation script in PHP and have gotten it working two ways. One way is slow but uses a limited amount of memory, the second is much faster, but uses 6x the memory . There is no leakage in either script (as far as I can tell).

In a limited benchmark, here is how they performed:

--------------------------------------------
METHOD  | TOTAL TIME | PEAK MEMORY |  IMAGES
--------------------------------------------
One     |     65.626 |     540,036 |     200
Two     |     20.207 |   3,269,600 |     200
--------------------------------------------

And here is the average of the previous numbers (if you don't want to do your own math):

--------------------------------------------
METHOD  | TOTAL TIME | PEAK MEMORY |  IMAGES
--------------------------------------------
One     |      0.328 |     540,036 |       1
Two     |      0.101 |   3,269,600 |       1
--------------------------------------------

Which method should I use and why?

I anticipate this being used by a high volume of users, with each user making 10-20 requests to this script during a normal visit.

I am leaning toward the faster method because though it uses more memory, it is for a 1/3 of the time and would reduce the number of concurrent requests.

© Stack Overflow or respective owner

Related posts about php

Related posts about optimization