[nycphp-talk] testing a theory
Adrian Noland
anoland at indigente.net
Wed Feb 7 14:33:41 EST 2007
On 2/7/07, Rob Marscher <rmarscher at beaffinitive.com> wrote:
> OK... I got interested enough to do a test myself. I ran it a few times
> with 100,000 loops of concatenating vs. echoing. The average result was
> about this:
> Concatenation took 0.13881587982178. Multiple echoes took 0.074604988098145.
> Concat mem usage was 1760704. Multiple echo mem usage was 901224.
> 58 milliseconds faster to do multiple echoes and uses about 839Kb less
> memory. I'm not sure how reliable get_memory_usage() is for
> benchmarking memory.
>
> By the way, in PHP5, you can just do:
> $starttime = microtime(true);
>
> But here's the source for my test that works in PHP4 and PHP5. You can
> change the iterations number and replace 'some text' with another string
> to try out different scenarios.
> Later,
> Rob
The loop is optimizing the results. Here is what I got when I replaced
them with 115K direct strings.
Without profiling
Concatenation took 4.47135686874. Multiple echoes took 5.18587899208.
Concatenation took 4.42481684685. Multiple echoes took 5.15758609772.
Concatenation took 4.42998504639. Multiple echoes took 5.14059782028.
with profiling enabled:
Concatenation took 7.02670788765. Multiple echoes took 7.44358682632
http://indigente.net/profile_microtime.profile.txt (7MB file)
http://indigente.net/profile_microtime.php.txt (10MB)
Obviously, I don't have any 10MB PHP files and this isn't a real world
example, but it is somewhat enlightening. I'm interested in
everybody's thoughts on this.
More information about the talk
mailing list