3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class HardcodedLocator { public function getFoo() { return null; } } class ConfigurableLocator { protected $services = array(); public function set( $name, $value ) { if ( isset( $this->services[$name] ) ) { throw new LogicException( 'Cannot redefine!' ); } $this->services[$name] = $value; } public function get( $name ) { if ( !isset( $this->services[$name] ) ) { throw new LogicException( 'No such service' ); } return $this->services[$name](); } } $hl = new HardcodedLocator(); $cl = new ConfigurableLocator(); $cl->set( 'foo', function() { return null; } ); $rounds = 10000; $htime = microtime( true ); for ( $i = 0; $i < $rounds; $i++ ) { $hl->getFoo(); } $htime = microtime( true ) - $htime; $ctime = microtime( true ); for ( $i = 0; $i < $rounds; $i++ ) { $cl->get( 'foo' ); } $ctime = microtime( true ) - $ctime; echo 'overhead: ' . ( ( $ctime - $htime ) / $rounds );
Output for 7.2.0
overhead: 8.0204010009766E-8
Output for 7.1.7
overhead: 6.256103515625E-8
Output for 7.1.6
overhead: 1.7433166503906E-7
Output for 7.1.5
overhead: 1.1551380157471E-7
Output for 7.1.0
overhead: 1.0471343994141E-7
Output for 7.0.20
overhead: 6.1392784118652E-8
Output for 7.0.6
overhead: 8.4209442138672E-8
Output for 7.0.5
overhead: 1.004695892334E-7
Output for 7.0.4
overhead: 6.7329406738281E-8
Output for 7.0.3
overhead: 6.5398216247559E-8
Output for 7.0.2
overhead: 6.4516067504883E-8
Output for 7.0.1
overhead: 9.7513198852539E-8
Output for 7.0.0
overhead: 5.7697296142578E-8
Output for 5.6.28
overhead: 2.3787021636963E-7
Output for 5.6.21
overhead: 1.9843578338623E-7
Output for 5.6.20
overhead: 1.4479160308838E-7
Output for 5.6.19
overhead: 2.1507740020752E-7
Output for 5.6.18
overhead: 2.0792484283447E-7
Output for 5.6.17
overhead: 1.4708042144775E-7
Output for 5.6.16
overhead: 1.5151500701904E-7
Output for 5.6.15
overhead: 1.4321804046631E-7
Output for 5.6.14
overhead: 2.8629302978516E-7
Output for 5.6.13
overhead: 2.2420883178711E-7
Output for 5.6.12
overhead: 2.302885055542E-7
Output for 5.6.11
overhead: 2.2962093353271E-7
Output for 5.6.10
overhead: 1.7707347869873E-7
Output for 5.6.9
overhead: 2.8040409088135E-7
Output for 5.6.8
overhead: 1.460075378418E-7
Output for 5.5.35
overhead: 2.2280216217041E-7
Output for 5.5.34
overhead: 2.0229816436768E-7
Output for 5.5.33
overhead: 2.504825592041E-7
Output for 5.5.32
overhead: 1.9271373748779E-7
Output for 5.5.31
overhead: 1.8367767333984E-7
Output for 5.5.30
overhead: 2.5858879089355E-7
Output for 5.5.29
overhead: 2.5601387023926E-7
Output for 5.5.28
overhead: 2.593994140625E-7
Output for 5.5.27
overhead: 2.4268627166748E-7
Output for 5.5.26
overhead: 2.5680065155029E-7
Output for 5.5.25
overhead: 2.1471977233887E-7
Output for 5.5.24
overhead: 2.424955368042E-7
Output for 5.4.45
overhead: 2.4209022521973E-7
Output for 5.4.44
overhead: 2.8269290924072E-7
Output for 5.4.43
overhead: 3.3988952636719E-7
Output for 5.4.42
overhead: 2.8908252716064E-7
Output for 5.4.41
overhead: 2.8989315032959E-7
Output for 5.4.40
overhead: 2.5017261505127E-7
Output for 5.4.39
overhead: 3.0930042266846E-7
Output for 5.4.38
overhead: 2.8951168060303E-7
Output for 5.4.37
overhead: 2.615213394165E-7
Output for 5.4.36
overhead: 2.3748874664307E-7
Output for 5.4.35
overhead: 2.6037693023682E-7
Output for 5.4.34
overhead: 2.8789043426514E-7
Output for 5.4.32
overhead: 3.0319690704346E-7
Output for 5.4.31
overhead: 2.5670528411865E-7
Output for 5.4.30
overhead: 2.3789405822754E-7
Output for 5.4.29
overhead: 2.3329257965088E-7
Output for 5.4.28
overhead: 2.4509429931641E-7
Output for 5.4.27
overhead: 2.4170875549316E-7
Output for 5.4.26
overhead: 2.8378963470459E-7
Output for 5.4.25
overhead: 2.9411315917969E-7
Output for 5.4.24
overhead: 2.3331642150879E-7
Output for 5.4.23
overhead: 2.741813659668E-7
Output for 5.4.22
overhead: 2.9048919677734E-7
Output for 5.4.21
overhead: 2.3708343505859E-7
Output for 5.4.20
overhead: 2.5398731231689E-7
Output for 5.4.19
overhead: 2.6311874389648E-7
Output for 5.4.18
overhead: 2.4559497833252E-7
Output for 5.4.17
overhead: 2.460241317749E-7
Output for 5.4.16
overhead: 3.4999847412109E-8
Output for 5.4.15
overhead: 3.2632350921631E-7
Output for 5.4.14
overhead: 2.5279521942139E-7
Output for 5.4.13
overhead: 2.0730495452881E-7
Output for 5.4.12
overhead: 2.6350021362305E-7
Output for 5.4.11
overhead: 3.2310485839844E-7
Output for 5.4.10
overhead: 5.1438808441162E-7
Output for 5.4.9
overhead: 2.6640892028809E-7
Output for 5.4.8
overhead: 2.5801658630371E-7
Output for 5.4.7
overhead: 3.061056137085E-7
Output for 5.4.6
overhead: 2.2671222686768E-7
Output for 5.4.5
overhead: 2.5761127471924E-7
Output for 5.4.4
overhead: 3.3349990844727E-7
Output for 5.4.3
overhead: 4.9529075622559E-7
Output for 5.4.2
overhead: 3.6830902099609E-7
Output for 5.4.1
overhead: 1.845121383667E-7
Output for 5.4.0
overhead: 3.5672187805176E-7
Output for 5.3.29
overhead: 3.8321018218994E-7
Output for 5.3.28
overhead: 4.5678615570068E-7
Output for 5.3.27
overhead: 4.5621395111084E-7
Output for 5.3.26
overhead: 4.8601627349854E-7
Output for 5.3.25
overhead: 4.8830509185791E-7
Output for 5.3.24
overhead: 7.8563690185547E-7
Output for 5.3.23
overhead: 8.0268383026123E-7
Output for 5.3.22
overhead: 6.3321590423584E-7
Output for 5.3.21
overhead: 5.4161548614502E-7
Output for 5.3.20
overhead: 5.2669048309326E-7
Output for 5.3.19
overhead: 3.9980411529541E-7