Skip to content

Instantly share code, notes, and snippets.

@Majkl578
Last active December 14, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Majkl578/5145846 to your computer and use it in GitHub Desktop.
Save Majkl578/5145846 to your computer and use it in GitHub Desktop.
PHP overlazyfying is evil Ilustrating cost of 1000 object instantiations on a large object (presenter) without constructor
<?php
require '/www/nette/Nette/loader.php';
class FooPresenter extends Nette\Application\UI\Presenter {}
$max = 1e3; // 1000
$foo = array_fill(1, $max, NULL);
$t = microtime(TRUE);
$m = memory_get_usage();
for ($i = 1; $i <= $max; ++$i) {
$foo[$i] = new FooPresenter();
}
var_dump(microtime(TRUE) - $t);
var_dump(memory_get_usage() - $m);
Without Zend Optimizer+:
float(0.0016729831695557)
int(609576)
With Zend Optimizer+:
float(0.0016708374023438)
int(610272)
-------------
Output?
Cost of an instantiation of a large object (Nette Presenter here) is about 0.000002 seconds and ~610 bytes.
@Majkl578
Copy link
Author

Updated pro Presenter (2.0.10) bez nastavení kontextu, předchozí verze zde.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment