rendered paste body<?php
sleep(1);
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
// DEOOP
function Abc_constructor(& $a,& $b,& $c)
{
$a = 5;
$b = 10;
$c = 15;
}
function Abc_add(& $a,& $b,& $c, $amount)
{
$a += $amount;
$b += $amount;
$c += $amount;
}
function Abc_multiplyA(& $a, $amount)
{
$a *= $amount;
}
function Abc_multiplyB(& $b, $amount)
{
$b *= $amount;
}
function Abc_multiplyC(& $c, $amount)
{
$c *= $amount;
}
// OOP
class Abc
{
public $a;
public $b;
public $c;
public $d;
function __construct()
{
$this->a = 5;
$this->b = 10;
$this->c = 15;
}
function add($amount)
{
$this->a += $amount;
$this->b += $amount;
$this->c += $amount;
}
function multiplyA($amount)
{
$this->a *= $amount;
}
function multiplyB($amount)
{
$this->b *= $amount;
}
function multiplyC($amount)
{
$this->c *= $amount;
}
}
// ---
$iterations = 100000;
$test = "deoop"; // <-- CHANGE THE STRING HERE
$t = microtime_float(true);
switch ($test) {
case "inlined":
for ($i=$iterations; $i--;) {
$x_a = NULL;
$x_b = NULL;
$x_c = NULL;
$x_d = NULL;
$x_a = 5;
$x_b = 10;
$x_c = 15;
$x_a += 1;
$x_b += 1;
$x_c += 1;
$x_a *= 3;
$x_b *= 3;
$x_c *= 3;
$x_d = $x_a + $x_b + $x_c;
}
echo $x_d.'<br>';
break;
case "deoop":
for ($i=$iterations; $i--;) {
$x_a = NULL;
$x_b = NULL;
$x_c = NULL;
$x_d = NULL;
Abc_constructor($x_a,$x_b,$x_c);
Abc_add($x_a,$x_b,$x_c,1);
Abc_multiplyA($x_a,3);
Abc_multiplyB($x_b,3);
Abc_multiplyC($x_c,3);
$x_d = $x_a + $x_b + $x_c;
}
echo $x_d.'<br>';
break;
case "oop":
for ($i=$iterations; $i--;) {
$x = new Abc();
$x->add(1);
$x->multiplyA(3);
$x->multiplyB(3);
$x->multiplyC(3);
$x->d = $x->a + $x->b + $x->c;
}
echo $x->d.'<br>';
break;
}
echo microtime_float(true) - $t;
?>