Skip to content

Instantly share code, notes, and snippets.

@Seldaek
Created December 16, 2010 14:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Seldaek/743433 to your computer and use it in GitHub Desktop.
float 3.8314838409424
float 2.6161198616028
<?php
class Field {
protected $a = 'a';
protected $b = 'b';
protected $c = 'c';
protected static $options = array('a', 'b');
public static function getOptions() {
return static::$options;
}
public static $options2 = array('a', 'b');
}
class SubField extends Field {
protected static $options = array('c');
public static $options2 = array('c');
}
class SubField2 extends Field {
}
$instance = new SubField2;
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
Field::getOptions();
SubField::getOptions();
SubField2::getOptions();
foreach (SubField2::getOptions() as $option) {
$reflProperty = new ReflectionProperty('SubField2', $option);
$reflProperty->setAccessible(true);
$reflProperty->getValue($instance);
}
}
var_dump(microtime(true) - $start);
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
if (isset(Field::$options2)) {
Field::$options2;
}
if (isset(SubField::$options2)) {
SubField::$options2;
}
if (isset(SubField2::$options2)) {
SubField2::$options2;
}
foreach (SubField2::$options2 as $option) {
$reflProperty = new ReflectionProperty('SubField2', $option);
$reflProperty->setAccessible(true);
$reflProperty->getValue($instance);
}
}
var_dump(microtime(true) - $start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment