Created
April 19, 2013 13:32
-
-
Save mageekguy/5420375 to your computer and use it in GitHub Desktop.
class_implements() vs reflection
This file contains hidden or 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 | |
class foo implements iteratorAggregate { function getIterator() {} } | |
$timeClassImplements = 0; | |
for ($i = 0; $i < 1000; $i++) | |
{ | |
$start = microtime(true); | |
class_implements('foo'); | |
$timeClassImplements += (microtime(true) - $start); | |
} | |
var_dump($timeClassImplements); | |
$timeReflection = 0; | |
for ($i = 0; $i < 1000; $i++) | |
{ | |
$class = new reflectionClass('foo'); | |
$start = microtime(true); | |
$class->getInterfaceNames(); | |
$timeReflection += (microtime(true) - $start); | |
} | |
var_dump($timeReflection); | |
var_dump($timeClassImplements - $timeReflection); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fch@Mageekbook:~
19> php -n test.php
float(0.00082540512084961)
float(0.00082063674926758)
float(4.7683715820312E-6)
fch@Mageekbook:~
20> php -v
PHP 5.4.13 (cli) (built: Apr 5 2013 08:55:20)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
fch@Mageekbook:~
21> php -m
[PHP Modules]
Core
ctype
date
dom
ereg
hash
json
libxml
mbstring
pcre
Phar
posix
readline
Reflection
session
SimpleXML
sockets
SPL
standard
tokenizer
xdebug
xhprof
xml
[Zend Modules]
Xdebug