Example #1
0
    Performance::measureCode(function () use($loops, $objectA) {
        // Set multiple: offsetSet
        for ($i = 0; $i < $loops; $i++) {
            $objectA['summary1'] = 'test' . $i;
            $objectA['summary2'] = 'test' . $i;
            $objectA['summary3'] = 'test' . $i;
        }
    });
    Performance::measureCode(function () use($loops, $objectA) {
        // Set multiple: setter
        for ($i = 0; $i < $loops; $i++) {
            $objectA->setVariable('summary1', 'test' . $i);
            $objectA->setVariable('summary2', 'test' . $i);
            $objectA->setVariable('summary3', 'test' . $i);
        }
    });
    Performance::measureCode(function () use($loops, $objectA) {
        // Set multiple: multi-setter
        for ($i = 0; $i < $loops; $i++) {
            $objectA->setVariables(['summary1' => 'test' . $i, 'summary2' => 'test' . $i, 'summary3' => 'test' . $i]);
        }
    });
    Performance::measureCode(function () use($loops, $objectB) {
        // Set multiple: __set w/ public var
        for ($i = 0; $i < $loops; $i++) {
            $objectB->summary1 = 'test' . $i;
            $objectB->summary2 = 'test' . $i;
            $objectB->summary3 = 'test' . $i;
        }
    });
})();
Example #2
0
use FixinTools\Performance\Magic\MethodsB;
(function () {
    include dirname(__DIR__, 3) . '/cheats/tools.php';
    $loops = 500000;
    $objectA = new MethodsA();
    $objectB = new MethodsB();
    Performance::measureCode(function () use($loops, $objectA) {
        // __call
        for ($i = 0; $i < $loops; $i++) {
            $objectA->escapeHtml('test' . $i);
        }
    });
    Performance::measureCode(function () use($loops, $objectA) {
        // __get
        for ($i = 0; $i < $loops; $i++) {
            ($objectA->escapeHtml)('test' . $i);
        }
    });
    Performance::measureCode(function () use($loops, $objectB) {
        // __get w/ public var
        for ($i = 0; $i < $loops; $i++) {
            ($objectB->escapeHtml)('test' . $i);
        }
    });
    Performance::measureCode(function () use($loops, $objectB) {
        // Existing method
        for ($i = 0; $i < $loops; $i++) {
            $objectB->existing('test' . $i);
        }
    });
})();