Lavoiesl\PhpBenchmark\Benchmark::run PHP Method

run() public method

public run ( $output = true )
    public function run($output = true)
    {
        $results = array();
        if (null === $this->n) {
            $this->guessCount(2);
            // aim for around 2 seconds per test
        }
        if ($output) {
            echo "Running tests {$this->n} times.\n";
        }
        $this->warmup();
        $i = 0;
        foreach ($this->tests as $name => $test) {
            if ($output) {
                echo "Testing " . ++$i . "/" . count($this->tests) . " : {$name}\r";
            }
            $results[$name] = $test->run($this->n);
        }
        if ($output) {
            echo "\n\n";
            self::outputTable(self::formatResults($results));
        }
        return $results;
    }

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::run