Metody v PHP jsou pomalé #fakt
This file contains 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 | |
class Foo1 | |
{ | |
public function bar() | |
{ | |
for ($i = 1000000; $i > 0; $i--) { | |
$result = $this->dance(); | |
} | |
} | |
public function dance() | |
{ | |
return (100 + 500) * 200; | |
} | |
} | |
class Foo2 | |
{ | |
public function bar() | |
{ | |
for ($i = 1000000 ; $i > 0 ; $i--) { | |
$result = (100 + 500) * 200; | |
} | |
} | |
} | |
$before = microtime(TRUE); | |
(new Foo1())->bar(); | |
echo sprintf("Separate method %sms\n", number_format((microtime(TRUE) - $before) * 1000, 2)); | |
$before = microtime(TRUE); | |
(new Foo2())->bar(); | |
echo sprintf("Inline method %sms\n", number_format((microtime(TRUE) - $before) * 1000, 2)); | |
This file contains 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 dukaz-misto-slibu.php | |
Separate method 955.29ms | |
Inline method 214.27ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment