Last active
August 29, 2015 14:04
-
-
Save hikari-no-yume/9a5ca0eb55a1d7918796 to your computer and use it in GitHub Desktop.
->call versus ->bindTo performance
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
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