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(); }
$phpCsFixer->run($parameter); } chdir(__DIR__); }, 'php-cs-fixer Symfony', "```bash\n\$ " . $phpCsFixer->getCommand() . "\n```"); $phpFmt = Exec::create('fmt.phar', '--dry-run', '--psr'); $unit->addClosure(function ($n, $parameter) use($phpFmt) { chdir($parameter); while ($n--) { $phpFmt->run($parameter); } chdir(__DIR__); }, 'phpfmt PSR-2', "```bash\n\$ " . $phpFmt->getCommand() . "\n```"); foreach ($repos as $repoName => $repo) { $repoDir = Path::combine($tmpDir, 'repo', $repoName); if (!is_dir($repoDir)) { $clone = Exec::create('git')->run('clone', '--depth=1', '--single-branch', $repo, $repoDir); } $reset = Exec::create('git')->run('--git-dir=' . $repoDir . '/.git', '--work-tree=' . $repoDir, 'reset', '--hard', 'HEAD'); $phpCsCache = Path::combine($repoDir, '.php_cs.cache'); if (is_file($phpCsCache)) { unlink($phpCsCache); } $phpCsConfig = Path::combine($repoDir, '.php_cs'); if (is_file($phpCsConfig)) { unlink($phpCsConfig); } $unit->addParam(new Parameter($repoDir, $repoName, "[{$repo}]({$repo})")); } $report->unitList->add($unit); $report->run();