Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created November 12, 2014 13:57
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 fprochazka/65bcc4874beaccbcc25a to your computer and use it in GitHub Desktop.
Save fprochazka/65bcc4874beaccbcc25a to your computer and use it in GitHub Desktop.
Metody v PHP jsou pomalé #fakt
<?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));
$ 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