Created
January 21, 2020 17:56
-
-
Save INDIAN2020/59c5c5db4c62c56b8ef24b83c9052e10 to your computer and use it in GitHub Desktop.
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
# Those are the results for 2 000 000 runs, and here is the code I used: | |
<?php | |
require '../vendor/autoload.php'; | |
// My small class to do benchmarks | |
// All it does is looping over every test x times and record the | |
// time it takes using `microtime(true)` | |
// Then, the percentage is calculated, with 100% being the quickest | |
// Times are being rouned for outputting only, not to calculate the percentages | |
$b = new Tleb\Benchmark\Benchmark(2000000); | |
class Foo | |
{ | |
public function calling_this() | |
{ | |
$this->called(); | |
} | |
public function calling_self() | |
{ | |
self::called(); | |
} | |
public function calling_static() | |
{ | |
static::called(); | |
} | |
public static function called() | |
{ | |
} | |
} | |
$b->add('$this->', function () { $foo = new Foo; $foo->calling_this(); }); | |
$b->add('self::', function () { $foo = new Foo; $foo->calling_self(); }); | |
$b->add('static::', function () { $foo = new Foo; $foo->calling_static(); }); | |
$b->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment