Lavoiesl\PhpBenchmark\Benchmark::add PHP Method

add() public method

Utility method to create tests on the fly You may chain the test:
public add ( string $name, Closure $closure ) : SimpleTest
$name string
$closure Closure function to execute
return SimpleTest
    public function add($name, \Closure $closure)
    {
        $test = new SimpleTest($name, $closure);
        $this->addTest($test);
        return $test;
    }

Usage Example

Beispiel #1
0
function bench($value, $n = 1000000)
{
    $benchmark = new Benchmark();
    $benchmark->add('serialize', function () use(&$value) {
        serialize($value);
    });
    $benchmark->add('json_encode', function () use(&$value) {
        json_encode($value);
    });
    if (function_exists('bin_encode')) {
        $benchmark->add('bin_encode', function () use(&$value) {
            bin_encode($value);
        });
    }
    if (function_exists('bson_encode')) {
        $benchmark->add('bson_encode', function () use(&$value) {
            bson_encode($value);
        });
    }
    if (function_exists('msgpack_pack')) {
        $benchmark->add('msgpack_pack', function () use(&$value) {
            msgpack_pack($value);
        });
    }
    if (function_exists('igbinary_serialize')) {
        $benchmark->add('igbinary_serialize', function () use(&$value) {
            igbinary_serialize($value);
        });
    }
    $benchmark->add('var_export', function () use(&$value) {
        var_export($value, true);
    });
    $benchmark->setCount($n);
    $benchmark->run();
}
All Usage Examples Of Lavoiesl\PhpBenchmark\Benchmark::add