Skip to content

Instantly share code, notes, and snippets.

@hikari-no-yume
Last active August 29, 2015 14:04
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 hikari-no-yume/9a5ca0eb55a1d7918796 to your computer and use it in GitHub Desktop.
Save hikari-no-yume/9a5ca0eb55a1d7918796 to your computer and use it in GitHub Desktop.
->call versus ->bindTo performance
andreas-air:php-src ajf$ time sapi/cli/php -r '$a = function () { return $this->x; }; class FooBar { private $x = 3; } $foobar = new FooBar; for ($i = 0; $i < 100000; $i++) { $x = $a->bindTo($foobar, "FooBar"); $x(); }'
real 0m0.259s
user 0m0.208s
sys 0m0.012s
andreas-air:php-src ajf$ time sapi/cli/php -r '$a = function () { return $this->x; }; $a = $a->bindTo(NULL, "FooBar", true); class FooBar { private $x = 3; } $foobar = new FooBar; for ($i = 0; $i < 100000; $i++) { $a->call($foobar); }'
real 0m0.100s
user 0m0.094s
sys 0m0.005s
// If we up the iterations by 10x, the result is the same:
andreas-air:php-src ajf$ time sapi/cli/php -r '$a = function () { return $this->x; }; class FooBar { private $x = 3; } $foobar = new FooBar; for ($i = 0; $i < 1000000; $i++) { $x = $a->bindTo($foobar, "FooBar"); $x(); }'
real 0m1.966s
user 0m1.959s
sys 0m0.005s
andreas-air:php-src ajf$ time sapi/cli/php -r '$a = function () { return $this->x; }; $a = $a->bindTo(NULL, "FooBar", true); class FooBar { private $x = 3; } $foobar = new FooBar; for ($i = 0; $i < 1000000; $i++) { $a->call($foobar); }'
real 0m0.962s
user 0m0.897s
sys 0m0.015s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment