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.
@fprochazka
Copy link

PHP 5.4.12 (cli) (built: Mar 12 2013 20:34:45) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
    with Zend Optimizer+ v7.0.0-dev, Copyright (c) 1999-2013, by Zend Technologies

new Nette\Forms\Form

double(0.035090923309326)
int(2907192)

new Nette\Application\UI\Presenter (bez injectu)

double(0.0015811920166016)
int(393128)

@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