Пример #1
0
 public function testReport()
 {
     Timer::$defaultMinDuration = 100;
     $report = new Report('Test report', 'Example benchmark.');
     $unit = new Unit('String concatenation');
     $unit->addClosure(function ($n) {
         while ($n--) {
             $x = "foobar {$n}";
         }
     }, '$x = "foobar $n"');
     $unit->addClosure(function ($n) {
         while ($n--) {
             $x = 'foobar ' . $n;
         }
     }, '$x = \'foobar \' . $n');
     $report->unitList->add($unit);
     $unit2 = new Unit('String concatenation with varying length');
     foreach ($unit->getMethods() as $method) {
         $unit2->addMethod($method);
     }
     $unit2->addParam(new Parameter('x', '$p = \'x\''));
     $unit2->addParam(new Parameter('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', '$p = \'xxxxx..\''));
     $report->unitList->add($unit2);
     $report->run();
 }
Пример #2
0
use nochso\Omni\Folder;
use nochso\Omni\Path;
require 'vendor/autoload.php';
$repos = ['aura/sql' => 'https://github.com/auraphp/Aura.Sql.git', 'doctrine/dbal' => 'https://github.com/doctrine/dbal.git', 'fzaninotto/faker' => 'https://github.com/fzaninotto/Faker.git', 'paris' => 'https://github.com/j4mie/paris.git', 'phpunit' => 'https://github.com/sebastianbergmann/phpunit.git', 'plates' => 'https://github.com/thephpleague/plates.git', 'slim' => 'https://github.com/slimphp/Slim.git', 'symfony/yaml' => 'https://github.com/symfony/yaml.git', 'twig' => 'https://github.com/twigphp/Twig.git'];
$tmpDir = Path::combine(sys_get_temp_dir(), 'phormat_benchmark');
Folder::ensure($tmpDir);
Timer::$defaultMinDuration = 1000;
$versions = ['phormat' => ['php', 'phormat', '-h'], 'php-cs-fixer' => ['php-cs-fixer', '--version'], 'phpfmt' => ['fmt.phar', '--version']];
foreach ($versions as $name => &$version) {
    $line = Exec::create()->run(...$version)->getOutput()[0];
    if (preg_match('/([0-9][0-9.-]+[0-9a-z-]+)/i', $line, $m)) {
        $version = $m[1];
    }
    $version = $name . ' ' . $version;
}
$report = new Report('Speed comparison of PHP source formatters', '', ['output_dir' => 'benchmark']);
$desc = 'Various open source projects are formatted with common settings.

Each repository is checked out `--hard` once before the benchmark is run.
`.php_cs` and `.php_cs_cache` files are removed to make php-cs-fixer comparable
with other formatters.

You can see the command arguments by clicking on the method.

Versions used:

* `' . implode("`\n* `", $versions) . '`';
$unit = new Unit('Formatting open source projects', $desc);
$phormat = Exec::create('php', 'phormat', '-n', '-s');
$unit->addClosure(function ($n, $parameter) use($phormat) {
    while ($n--) {