Created
August 26, 2015 02:17
-
-
Save joshuaadickerson/6802207aeef90cb7c88f to your computer and use it in GitHub Desktop.
I am getting a memory exhaustion while creating objects that aren't assigned to variables. This is the tests for that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** RESULTS: Closures and str_repeat() | |
| php /var/www/BBC/Test.php | |
| Test started | |
| 0 || 263152 | |
| 1000 || 485437312 | |
| 2000 || 970686632 | |
| 3000 || 1458032936 | |
| 4000 || 1941184936 | |
| 5000 || 2432725544 | |
| Killed | |
| */ | |
| class Test | |
| { | |
| public $test; | |
| public $closures = array(); | |
| public function __construct() | |
| { | |
| $this->repeat(); | |
| $this->closures(); | |
| } | |
| public function repeat() | |
| { | |
| $this->test = str_repeat('lorem ipsum lorem ipsum lorem ipsum lorem ipsum', 10000); | |
| } | |
| public function closures() | |
| { | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| } | |
| } | |
| set_time_limit(0); | |
| echo "Test started\n"; | |
| for($i = 0; $i < 1000000; $i++) | |
| { | |
| if ($i % 1000 === 0) | |
| { | |
| echo $i . ' || ' . memory_get_peak_usage() . "\n"; | |
| } | |
| new Test; | |
| } | |
| ?>Test complete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** RESULTS no closures | |
| What's the difference between 0, 100k, and 200k? | |
| # php /var/www/BBC/Test.php | |
| Test started | |
| 0 || 262816 | |
| 100000 || 723208 | |
| 200000 || 723248 | |
| 300000 || 723248 | |
| 400000 || 723248 | |
| 500000 || 723248 | |
| 600000 || 723248 | |
| 700000 || 723248 | |
| 800000 || 723248 | |
| 900000 || 723248 | |
| Test complete | |
| */ | |
| class Test | |
| { | |
| public $test; | |
| public $closures = array(); | |
| public function __construct() | |
| { | |
| $this->repeat(); | |
| //$this->closures(); | |
| } | |
| public function repeat() | |
| { | |
| $this->test = str_repeat('lorem ipsum lorem ipsum lorem ipsum lorem ipsum', 10000); | |
| } | |
| public function closures() | |
| { | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| } | |
| } | |
| set_time_limit(0); | |
| echo "Test started\n"; | |
| for($i = 0; $i < 1000000; $i++) | |
| { | |
| if ($i % 100000 === 0) | |
| { | |
| echo $i . ' || ' . memory_get_peak_usage() . "\n"; | |
| } | |
| new Test; | |
| } | |
| ?>Test complete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** RESULTS no str_repeat() | |
| # php /var/www/BBC/Test.php | |
| Test started | |
| 0 || 263256 | |
| 100000 || 164567160 | |
| 200000 || 164567656 | |
| 300000 || 164568416 | |
| 400000 || 164569400 | |
| 500000 || 164569896 | |
| 600000 || 164570648 | |
| 700000 || 164571368 | |
| 800000 || 164572136 | |
| 900000 || 164573608 | |
| Test complete | |
| */ | |
| class Test | |
| { | |
| public $test; | |
| public $closures = array(); | |
| public function __construct() | |
| { | |
| //$this->repeat(); | |
| $this->closures(); | |
| } | |
| public function repeat() | |
| { | |
| $this->test = str_repeat('lorem ipsum lorem ipsum lorem ipsum lorem ipsum', 10000); | |
| } | |
| public function closures() | |
| { | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| $this->closures[] = function() { echo 'this is just a closure'; }; | |
| } | |
| } | |
| set_time_limit(0); | |
| echo "Test started\n"; | |
| for($i = 0; $i < 1000000; $i++) | |
| { | |
| if ($i % 100000 === 0) | |
| { | |
| echo $i . ' || ' . memory_get_peak_usage() . "\n"; | |
| } | |
| new Test; | |
| } | |
| ?>Test complete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** RESULTS no str_repeat() with closures being assigned to a local variable, not a property | |
| # php /var/www/BBC/Test.php | |
| Test started | |
| 0 || 262216 | |
| 100000 || 262216 | |
| 200000 || 262216 | |
| 300000 || 262216 | |
| 400000 || 262216 | |
| 500000 || 262216 | |
| 600000 || 262216 | |
| 700000 || 262216 | |
| 800000 || 262216 | |
| 900000 || 262216 | |
| Test complete | |
| */ | |
| class Test | |
| { | |
| public $test; | |
| public $closures = array(); | |
| public function __construct() | |
| { | |
| //$this->repeat(); | |
| $this->closures(); | |
| } | |
| public function repeat() | |
| { | |
| $this->test = str_repeat('lorem ipsum lorem ipsum lorem ipsum lorem ipsum', 10000); | |
| } | |
| public function closures() | |
| { | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| $closure = function() { echo 'this is just a closure'; }; | |
| } | |
| } | |
| set_time_limit(0); | |
| echo "Test started\n"; | |
| for($i = 0; $i < 1000000; $i++) | |
| { | |
| if ($i % 100000 === 0) | |
| { | |
| echo $i . ' || ' . memory_get_peak_usage() . "\n"; | |
| } | |
| new Test; | |
| } | |
| ?>Test complete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment