Created
January 18, 2016 03:11
-
-
Save hasyimibhar/691983fe65d4f0eee5a1 to your computer and use it in GitHub Desktop.
Benchmark of calling ReflectionMethod::getParameters
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 | |
ini_set('memory_limit', '-1'); | |
$n = 1000000; | |
class A {} | |
class B {} | |
class C {} | |
class D {} | |
class E {} | |
class F {} | |
class G {} | |
class H {} | |
class I {} | |
class J {} | |
class Foo | |
{ | |
public function bar(A $a, B $b, C $c, D $d, E $e, F $f, G $g, H $h, I $i, J $j) | |
{ | |
// .. | |
} | |
} | |
$foo = new Foo(); | |
$times = []; | |
for ($i = 0; $i < $n; $i++) { | |
$start = microtime(true); | |
$ref = new ReflectionMethod($foo, 'bar'); | |
$params = $ref->getParameters(); | |
$end = microtime(true); | |
$times[] = $end - $start; | |
} | |
$avg = array_sum($times) / $n; | |
echo "Average of $n: " . number_format($avg, 10) . " sec, or " . number_format($avg * 1000000, 10) . " usec\n"; |
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
Average of 1000000: 0.0000090445 sec, or 9.0445024967 usec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample benchmark ran on: