run() public method

public run ( $output = true )
Exemplo n.º 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();
}
Exemplo n.º 2
0
function bench($value, $n = 1000000)
{
    $benchmark = new Benchmark();
    $serialized = serialize($value);
    $benchmark->add('unserialize', function () use(&$serialized) {
        unserialize($serialized);
    });
    $jsonEncoded = json_encode($value);
    $benchmark->add('json_decode', function () use(&$jsonEncoded) {
        json_decode($jsonEncoded);
    });
    if (function_exists('bin_decode')) {
        $binEncoded = bin_encode($value);
        $benchmark->add('bin_decode', function () use(&$binEncoded) {
            bin_decode($binEncoded);
        });
    }
    if (function_exists('bson_decode')) {
        $bsonEncoded = bson_encode($value);
        $benchmark->add('bson_decode', function () use(&$bsonEncoded) {
            bson_decode($bsonEncoded);
        });
    }
    if (function_exists('msgpack_pack')) {
        $msgPack = msgpack_pack($value);
        $benchmark->add('msgpack_unpack', function () use(&$msgPack) {
            msgpack_unpack($msgPack);
        });
    }
    if (function_exists('igbinary_unserialize')) {
        $igbinarySerialized = igbinary_serialize($value);
        $benchmark->add('igbinary_unserialize', function () use(&$igbinarySerialized) {
            igbinary_unserialize($igbinarySerialized);
        });
    }
    $benchmark->setCount($n);
    $benchmark->run();
}
EventLoop::$instance = new EventLoop();
class A
{
    protected $ev;
    public function __construct(EventLoop $ev)
    {
        $this->ev = $ev;
    }
    public function test()
    {
        return $this->ev;
    }
}
class B
{
    public function test()
    {
        return EventLoop::$instance;
    }
}
$aInstance = new A(new EventLoop());
$benchmark->add('without-static-normal-injection', function () use($aInstance) {
    return $aInstance->test();
});
$bInstance = new B();
$benchmark->add('with-static-global-state', function () use($bInstance) {
    return $bInstance->test();
});
$benchmark->setCount(10000000);
$benchmark->run();
<?php

/**
 * Created by PhpStorm.
 * User: ovr
 * Date: 06.12.15
 * Time: 22:26
 */
use Lavoiesl\PhpBenchmark\Benchmark;
use Ovr\Bench\AssignOrNot\ReturnAfterAssignProperty;
use Ovr\Bench\AssignOrNot\ReturnWithoutAfterAssignProperty;
include_once __DIR__ . '/vendor/autoload.php';
class User
{
    const STATUS_ACTIVE = 'active';
    public $status;
}
$benchmark = new Benchmark();
$user = new User();
$user->status = User::STATUS_ACTIVE;
$benchmark->add('$a == $b', function () use($user) {
    return $user->status == User::STATUS_ACTIVE;
});
$benchmark->add('$a === $b', function () use($user) {
    return $user->status === User::STATUS_ACTIVE;
});
$benchmark->run(100000000000);