@ 2017-06-06T20:38:17Z <?php
if (substr(PHP_VERSION, 0, 5) !== '7.1.5') die('Meh');
function test($label = '') {
global $t;
$t2 = microtime(1);
if ($label) echo str_pad($label . ': ', 32, '.', STR_PAD_RIGHT) . ' ' . 1000 * ($t2 - $t) . 'ms' . "\n";
$t = $t2;
}
class A {
protected $_val = 123;
function getVal() {
return $this->_val;
}
function setVal($val) {
$this->_val = $val;
}
}
class A2 {
protected $_val = 123;
function getVal() {
return $this->_val;
}
function setVal($val) {
$this->_val = $val;
}
function __get($name) {
return $this->{'__get_' . $name}($name);
}
function __set($name, $value) {
$this->{'__set_' . $name}($value);
}
}
class B {
protected $val = 123;
function __get($name) {
return $this->{'__get_' . $name}($name);
}
function __set($name, $value) {
$this->{'__set_' . $name}($value);
}
function __get_val() {
return $this->val;
}
function __set_val($val) {
$this->val = $val;
}
}
class C {
protected $val = 123;
function __get($name) {
return $this->val;
}
function __set($name, $value) {
$this->val = $value;
}
}
class D {
public $val;
function __construct() {
$this->val = new Prop(123);
}
}
class D2 {
public $val;
protected $_val = 123;
function __construct() {
$this->val = new Prop2(function () {
return $this->_val;
}, function ($value) {
$this->_val = $value;
});
}
}
class Prop {
protected $_val = 123;
function __construct($val) {
$this->_val = $val;
}
function get() {
return $this->_val;
}
function set($val) {
$this->_val = $val;
}
}
class Prop2 {
protected $get;
protected $set;
function __construct($get, $set) {
$this->get = $get;
$this->set = $set;
}
function get() {
return ($this->get)();
}
function set($val) {
($this->set)($val);
}
}
class E {
public $val = 123;
}
$c = 1000000;
test();
$x = new A();
for ($i = $c; $i--;) {
$a = $x->getVal();
$x->setVal(321);
}
test('methods');
$x = new A2();
for ($i = $c; $i--;) {
$a = $x->getVal();
$x->setVal(321);
}
test('methods + passive magic');
$x = new B();
for ($i = $c; $i--;) {
$a = $x->val;
$x->val = 321;
}
test('magic');
$x = new C();
for ($i = $c; $i--;) {
$a = $x->val;
$x->val = 321;
}
test('light magic');
$x = new D();
for ($i = $c; $i--;) {
$a = $x->val->get();
$x->val->set(321);
}
test('nested object');
$x = new D2();
for ($i = $c; $i--;) {
$a = $x->val->get();
$x->val->set(321);
}
test('nested proxy');
$x = new E();
for ($i = $c; $i--;) {
$a = $x->val;
$x->val = 321;
}
test('property');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.2.0 0.007 0.007 19.14 7.1.7 0.005 0.002 16.94 7.1.6 0.176 0.003 15.24 7.1.5 0.077 1.572 32.78 7.1.4 0.040 0.017 32.58 7.1.3 0.053 0.020 32.64 7.1.2 0.043 0.017 32.68 7.1.1 0.037 0.010 14.55 7.1.0 0.040 0.007 14.67 7.0.20 0.016 0.006 16.64 7.0.19 0.047 0.007 14.65 7.0.18 0.043 0.003 14.34 7.0.17 0.050 0.007 14.25 7.0.16 0.057 0.010 14.45 7.0.15 0.040 0.003 14.32 7.0.14 0.050 0.007 14.56 7.0.13 0.037 0.007 14.57 7.0.12 0.033 0.010 14.48 7.0.11 0.033 0.010 14.41 7.0.10 0.040 0.003 14.35 7.0.9 0.033 0.010 14.52 7.0.8 0.030 0.010 14.42 7.0.7 0.030 0.010 14.54 7.0.6 0.033 0.013 14.24 7.0.5 0.040 0.013 14.23 7.0.4 0.033 0.007 14.59 7.0.3 0.097 0.010 14.50 7.0.2 0.030 0.007 14.48 7.0.1 0.030 0.010 14.45 7.0.0 0.033 0.010 14.54
preferences:dark mode live preview
29.36 ms | 401 KiB | 5 Q