Re: The way the engine works?
| From: | Rasmus Lerdorf | Date: | Mon, 05 Mar 2007 23:00:36 +0000 |
| Subject: | Re: The way the engine works? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-28253@lists.php.net to get a copy of this message | ||
Brian Moon wrote:
> Antony Dovgal wrote:
>> Yup, the language stole ~32Kb of your memory and used it to speedup
>> the allocation of small chunks.
>
> Ok, in my attempt to send a sane looking example, I cleaned up the problem.
>
> <?php
>
> $str = "This is a medium length string";
>
> $start = memory_get_usage();
> for($x=1;$x<=1000000;$x++){
> $var = $str." ".$x.": (3.5): ".time()."\n";
> }
> $first_growth = number_format(memory_get_usage() - $start);
>
> $start = memory_get_usage();
> for($x=1;$x<=1000000;$x++){
> $var = "$str $x: (3.5): ".time()."\n";
> }
> $growth = number_format(memory_get_usage() - $start);
>
>
> echo "first growth: $first_growth\nsecond growth: $growth\n";
>
> ?>
>
> The introduction of $x into the string makes the difference.
>
> first growth: 892
> second growth: 3,955,068
I get:
first growth: 704
second growth: 32,264
with current PHP_5_2 checkout. I don't have a 5.1.x handy with memory
limits compiled in.
-Rasmus