Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
lazy output added
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Mar 11, 2016
1 parent 26608a7 commit 959ad5a
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ protected function _timeFormat($time, $decimal = 3)
*/
public function out($message, $addEol = true)
{
Cli::out($message, $addEol);
if (function_exists('\JBZoo\PHPUnit\cliMessage')) {
\JBZoo\PHPUnit\cliMessage($message, $addEol);
} else {
Cli::out($message, $addEol);
}
}

/**
Expand All @@ -288,27 +292,27 @@ public static function compare($tests, $options)
), $options);

// Prepare
$benchmark = new Benchmark();
$benchmark->setCount($options['count']);
$bench = new Benchmark();
$bench->setCount($options['count']);
foreach ($tests as $testName => $function) {
$benchmark->add($testName, $function);
$bench->add($testName, $function);
}
declare(ticks = 1);

// Run tests
$wrapProfiler = new Profiler();

if ($options['output']) {
Cli::out(PHP_EOL . '<pre>--------------- Start compare bench: ' . $options['name'] . ' ---------------');
$bench->out(PHP_EOL . '<pre>--------------- Start compare: ' . $options['name'] . ' ---------------');
$wrapProfiler->start(false);
$result = $benchmark->run(true);
$result = $bench->run(true);
$wrapProfiler->stop();
Cli::out(PHP_EOL . 'TOTAL: ' . $wrapProfiler->getTotalUsage());
Cli::out('-------------------- Finish compare bench: ' . $options['name'] . ' ---------</pre>' . PHP_EOL);
$bench->out(PHP_EOL . 'TOTAL: ' . $wrapProfiler->getTotalUsage());
$bench->out('-------------------- Finish compare: ' . $options['name'] . ' ---------</pre>' . PHP_EOL);

} else {
$wrapProfiler->start(false);
$result = $benchmark->run(false);
$result = $bench->run(false);
$wrapProfiler->stop();
}

Expand All @@ -335,20 +339,20 @@ public static function one($test, $options)
), $options);

// Prepare
$benchmark = new Benchmark();
$benchmark->setCount($options['count']);
$benchmark->add('Test', $test);
$bench = new Benchmark();
$bench->setCount($options['count']);
$bench->add('Test', $test);
declare(ticks = 1);

// Run tests
$wrapProfiler = new Profiler();
$wrapProfiler->start(false);
if ($options['output']) {
Cli::out(PHP_EOL . '<pre>--------------- Start one bench: ' . $options['name'] . ' ---------------');
$result = $benchmark->run(true);
Cli::out('-------------------- Finish one bench: ' . $options['name'] . ' ---------</pre>' . PHP_EOL);
$bench->out(PHP_EOL . '<pre>--------------- Start one bench: ' . $options['name'] . ' ---------------');
$result = $bench->run(true);
$bench->out('-------------------- Finish one bench: ' . $options['name'] . ' ---------</pre>' . PHP_EOL);
} else {
$result = $benchmark->run(false);
$result = $bench->run(false);
}

$wrapProfiler->stop();
Expand Down

0 comments on commit 959ad5a

Please sign in to comment.