Beispiel #1
0
/**
 * This file is part of Benchmark
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Nicolò Martini <*****@*****.**>
 */
include '../vendor/autoload.php';
ini_set('xdebug.var_display_max_depth', '10');
function func()
{
}
$func = 'func';
$bench = new \Nicmart\Benchmark\FixedSizeEngine();
$args = array_fill(0, 5, null);
$bench->register('direct', 'Direct call', function () use($args) {
    func($args[0], $args[1], $args[2], $args[3], $args[4]);
}, true)->register('cuf', 'call_user_func', function () use($args) {
    call_user_func('func', $args[0], $args[1], $args[2], $args[3], $args[4]);
}, true)->register('cufa', 'call_user_func_array', function () use($args) {
    call_user_func_array('func', $args);
});
$bench->benchmark(100);
$bench->benchmark(100);
$bench->benchmark(100);
$bench->benchmark(100);
$bench->benchmark(1000);
$groups[] = $bench->getResults();
$template = new \Nicmart\Benchmark\PHPTemplate();
Beispiel #2
0
}, "name and age" => function (Person $p) {
    $age = date("Y") - $p->getBirthYear();
    return "{$p->getFirstName()} {$p->getFirstName()}, {$age}";
}]);
$adapted = new \NicMart\Arrayze\ArrayAdapter($person, $collection);
$bench = new \Nicmart\Benchmark\FixedSizeEngine("Arrayze Benchmark - Single Lookup");
$bench->register('native', 'Native closure', function () use($toArray, $person) {
    $ary = $toArray($person);
    $string = $ary["full name"];
}, true)->register('arrayze', 'Arrayze', function () use($person, $collection) {
    $adapted = new \NicMart\Arrayze\ArrayAdapter($person, $collection);
    $string = $adapted["full name"];
}, true);
$bench->benchmark(100000);
$groups[] = $bench->getResults();
$bench = new \Nicmart\Benchmark\FixedSizeEngine("Arrayze Benchmark - Iteration");
$bench->register('native', 'Native closure', function () use($toArray, $person) {
    $ary = $toArray($person);
    $string = "";
    foreach ($ary as $key => $value) {
        $string .= "{$key}: {$value}, ";
    }
}, true)->register('arrayze', 'Arrayze', function () use($person, $collection) {
    $adapted = new \NicMart\Arrayze\ArrayAdapter($person, $collection);
    $string = "";
    foreach ($adapted as $key => $value) {
        $string .= "{$key}: {$value}, ";
    }
}, true);
$bench->benchmark(100000);
$groups[] = $bench->getResults();
Beispiel #3
0
<?php

/**
 * This file is part of Benchmark
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Nicolò Martini <*****@*****.**>
 */
include '../vendor/autoload.php';
ini_set('xdebug.var_display_max_depth', '10');
$bench = new \Nicmart\Benchmark\FixedSizeEngine("Arrays vs Classes");
$storage = array();
$storage2 = array();
class Test
{
    public $field0;
    public $field1;
    public $field2;
    public $field3;
    public $field4;
    public $field5;
    public $field6;
    public $field7;
    public $field8;
    public $field9;
}
$bench->register('plain array', 'Plain Array', function () {
    $a = array();
    $a["field0"] = 0;
Beispiel #4
0
/**
 * This file is part of Benchmark
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Nicolò Martini <*****@*****.**>
 */
include '../vendor/autoload.php';
ini_set('xdebug.var_display_max_depth', '10');
function func()
{
}
$func = 'func';
$bench = new \Nicmart\Benchmark\FixedSizeEngine('Isset versus null');
$args = array('a', null);
$bench->register('isset', 'isset', function () use($args) {
    $a = isset($args[0]);
    $b = isset($args[1]);
}, true)->register('null', 'null', function () use($args) {
    $a = $args[0] === null;
    $b = $args[1] === null;
}, true)->register('is_null', 'is_null', function () use($args) {
    $a = is_null($args[0]);
    $b = is_null($args[1]);
})->register('array_key_exists', 'array_key_exists', function () use($args) {
    $a = array_key_exists(0, $args);
    $b = array_key_exists(1, $args);
});
$bench->benchmark(50000);