本文整理汇总了PHP中PHP_Timer类的典型用法代码示例。如果您正苦于以下问题:PHP PHP_Timer类的具体用法?PHP PHP_Timer怎么用?PHP PHP_Timer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHP_Timer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: printResult
/**
* Prints a result set from PHPDCD_Detector::detectDeadCode().
*
* @param array $result
* @param string $commonPath
*/
public function printResult(array $result, $commonPath)
{
foreach ($result as $name => $source) {
printf("\n - %s()\n declared in %s:%d\n", $name, str_replace($commonPath, '', $source['file']), $source['line']);
}
print "\n" . PHP_Timer::resourceUsage() . "\n";
}
示例2: run
public function run(\PHPUnit_Framework_TestResult $result = null)
{
if (!$result) {
$result = new \PHPUnit_Framework_TestResult();
}
$opt = null;
\PHP_Timer::start();
$result->startTest($this);
try {
$opt = \Docopt::handle($this->doc, array('argv' => $this->argv, 'exit' => false));
} catch (\Exception $ex) {
// gulp
}
$found = null;
if ($opt) {
if (!$opt->success) {
$found = array('user-error');
} elseif (empty($opt->args)) {
$found = array();
} else {
$found = $opt->args;
}
}
$time = \PHP_Timer::stop();
try {
\PHPUnit_Framework_Assert::assertEquals($this->expect, $found);
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
$result->addFailure($this, $e, $time);
}
$result->endTest($this, $time);
return $result;
}
示例3: run
public function run(\PHPUnit_Framework_TestResult $result = null)
{
if (!$result) {
$result = new \PHPUnit_Framework_TestResult();
}
$reader = new \Fulfil\Test\SpecTest\Reader();
$tests = $reader->read($testFile);
foreach ($tests as $test) {
foreach ($test->data as $case) {
\PHP_Timer::start();
$result->startTest($this);
try {
$ctx = new \Fulfil\Context();
$test->test->apply($case->in, $ctx);
$flat = $ctx->flatten();
} catch (\Exception $ex) {
// yum
}
$time = \PHP_Timer::stop();
try {
\PHPUnit_Framework_Assert::assertEquals($case->valid, $flat->valid);
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
$result->addFailure($this, $e, $time);
}
$result->endTest($this, $time);
}
}
return $result;
}
示例4: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (\App::environment() === 'production') {
$this->error('This feature is not available on this server');
}
$command = base_path('vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'apigen') . ' generate -s app -d phpdoc';
$this->comment($command);
$process = new Process($command);
$process->run(function ($type, $buffer) {
$buffer = trim($buffer);
if (empty($buffer)) {
return;
}
if ('err' === $type) {
$this->error($buffer);
} else {
$this->comment($buffer);
}
});
if (!$process->isSuccessful()) {
$this->error($process->getErrorOutput());
return;
}
$this->comment('Documentation generated in folder ' . base_path('phpdoc'));
$this->comment(\PHP_Timer::resourceUsage());
}
示例5: printFooter
protected function printFooter(PHPUnit_Framework_TestResult $result)
{
$this->write('<div class="stats">');
parent::printFooter($result);
$this->write('</div>');
$this->write('<div class="resourceUsage">');
$this->write(PHP_Timer::resourceUsage());
$this->write('</div>');
}
示例6: twigRender
public function twigRender($template, $output = [])
{
$output['resources'] = \PHP_Timer::resourceUsage();
$fullPath = $this->templatePath . $template;
$templateFile = strrchr($fullPath, DS);
$loader = new \Twig_Loader_Filesystem(str_replace($templateFile, '', $fullPath));
$twig = new \Twig_Environment($loader);
return $twig->render($templateFile, $output);
}
示例7: renderTwig
public function renderTwig($layout, $params = [])
{
$time = \PHP_Timer::resourceUsage();
$params['time'] = $time;
$loader = new \Twig_Loader_Filesystem([str_replace('\\', '/', __DIR__ . '/layouts'), str_replace('\\', '/', __DIR__ . '/templates')]);
$twig = new \Twig_Environment($loader, ['cache' => false]);
$content = $twig->render($layout, $params);
return $content;
}
示例8: __invoke
/**
* Example middleware invokable class.
*
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
* @param callable $next Next middleware
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function __invoke(Request $request, Response $response, callable $next)
{
// Start the timer at the beginning of the request
\PHP_Timer::start();
$response = $next($request, $response);
// Log the results
$this->logger->info($request->getUri()->getAuthority() . ' ' . $request->getHeaderLine('AUTH_PRINCIPAL') . ' ' . $request->getAttribute('ip_address') . ' ' . $request->getMethod() . ' ' . $request->getUri()->getPath() . ' ' . $response->getStatusCode() . ' ' . $request->getBody()->getSize() . ' ' . $response->getBody()->getSize() . ' ' . \PHP_Timer::stop());
return $response;
}
示例9: testArrays
public function testArrays()
{
$total = 1000000;
$try1 = array_fill(0, $total, 1);
$try1[rand(0, count($try1) - 1)] = null;
$try2 = array_fill(0, $total, 1);
$try2[rand(0, count($try1) - 1)] = null;
$try2[(string) count($try2)] = 'value';
$uk = rand(0, $total);
unset($try2[$uk]);
print 'isSequentialFastest:' . PHP_EOL;
\PHP_Timer::start();
$isHashFalse = !ArrayStructure::isSequentialFastest($try1);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
\PHP_Timer::start();
$isHashTrue = !ArrayStructure::isSequentialFastest($try2);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
$this->assertFalse($isHashFalse);
$this->assertTrue($isHashTrue);
print 'isSequentialSimple:' . PHP_EOL;
\PHP_Timer::start();
$isSeqFalse = !ArrayStructure::isSequentialSimple($try1);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
\PHP_Timer::start();
$isSeqTrue = !ArrayStructure::isSequentialSimple($try2);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
$this->assertFalse($isSeqFalse);
$this->assertTrue($isSeqTrue);
print 'isSequentialExotic:' . PHP_EOL;
\PHP_Timer::start();
$isSeqTrue = ArrayStructure::isSequentialExotic($try1);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
\PHP_Timer::start();
$isSeqFalse = ArrayStructure::isSequentialExotic($try2);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
$this->assertFalse($isSeqFalse);
$this->assertTrue($isSeqTrue);
print 'isAssoc:' . PHP_EOL;
\PHP_Timer::start();
$isAssocFalse = ArrayStructure::isAssoc($try1);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
\PHP_Timer::start();
$isAssocTrue = ArrayStructure::isAssoc($try2);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
$this->assertFalse($isAssocFalse);
$this->assertTrue($isAssocTrue);
}
示例10: actionOne
/**
* Метод вывода одной новости по её id
*
*/
protected function actionOne()
{
$id = (int) $_GET['id'] ?: false;
if (empty($id)) {
$this->redirect('/');
}
if (!empty($article = NewsModel::findById($id))) {
$this->view->render('/news/one.html', ['article' => $article, 'resource' => \PHP_Timer::resourceUsage()]);
} else {
$this->view->erroradmin = false;
throw new Exception404('Страница с такой новостью не найдена');
}
}
示例11: testPersistentResourceSimulation
public function testPersistentResourceSimulation()
{
PHP_Timer::start();
$movie = new ffmpeg_movie(self::$moviePath, true);
$movie = new ffmpeg_movie(self::$moviePath, true);
$movie = new ffmpeg_movie(self::$moviePath, true);
$elapsed = PHP_Timer::stop();
PHP_Timer::start();
$movie = new ffmpeg_movie(self::$moviePath);
$movie = new ffmpeg_movie(self::$moviePath);
$movie = new ffmpeg_movie(self::$moviePath);
$elapsed1 = PHP_Timer::stop();
$this->assertGreaterThan($elapsed, $elapsed1, 'Persistent resource simulation should be faster');
}
示例12: __construct
/**
* Class constructor for full/combined report
*
* @param string $source Data source
* @param array $options Options for parser
* @param array $warnings List of warning messages already produced
* @param array $reportChilds List of reports to print
*/
public function __construct($source, $options, $warnings, $reportChilds)
{
$pci = new PHP_CompatInfo($options);
if ($pci->parse($source) === false) {
return;
}
$reportResults = $pci->toArray();
$masterResults = $reportResults[0];
if ($options['verbose'] < 3) {
$reportResults = $reportResults[0];
} else {
unset($reportResults[0]);
}
$base = realpath($source);
if (is_file($base)) {
$base = dirname($base);
}
$allWarnings = array_unique(array_merge($warnings, $pci->getWarnings()));
$options = $pci->getOptions();
if (empty($reportChilds)) {
$reportChilds = array('summary', 'extension', 'interface', 'trait', 'class', 'function', 'constant', 'global', 'token', 'condition');
}
foreach ($reportChilds as $report) {
$classReport = 'PHP_CompatInfo_Report_' . ucfirst($report);
new $classReport($source, $options, $allWarnings, $reportResults);
}
echo PHP_EOL;
if (count($allWarnings) > 0 && $options['verbose'] > 0) {
echo 'Warning messages : (' . count($allWarnings) . ')' . PHP_EOL;
echo PHP_EOL;
foreach ($allWarnings as $warn) {
if (in_array($warn, $warnings)) {
// other listeners need to be notifed about console warnings
$pci->addWarning($warn);
}
echo ' ' . $warn . PHP_EOL;
}
echo PHP_EOL;
}
if (class_exists('PHP_Timer', true) === true) {
echo PHP_Timer::resourceUsage() . PHP_EOL;
echo PHP_EOL;
}
echo 'Required PHP ' . $masterResults['versions'][0] . ' (min)';
if (!empty($masterResults['versions'][1])) {
echo ', ' . $masterResults['versions'][1] . ' (max)';
}
echo PHP_EOL;
}
示例13: run
public function run(PHPUnit_Framework_TestResult $result = null)
{
PHPUnit_Framework_Assert::resetCount();
if ($result === NULL) {
$result = new PHPUnit_Framework_TestResult();
}
$this->suite->publishTestArticles();
// Add articles needed by the tests.
$backend = new ParserTestSuiteBackend();
$result->startTest($this);
// Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
if (class_exists('PHP_Timer')) {
PHP_Timer::start();
} else {
PHPUnit_Util_Timer::start();
}
$r = false;
try {
# Run the test.
# On failure, the subclassed backend will throw an exception with
# the details.
$pt = new PHPUnitParserTest();
$r = $pt->runTest($this->test['test'], $this->test['input'], $this->test['result'], $this->test['options'], $this->test['config']);
} catch (PHPUnit_Framework_AssertionFailedError $e) {
// PHPUnit_Util_Timer -> PHP_Timer support (see above)
if (class_exists('PHP_Timer')) {
$result->addFailure($this, $e, PHP_Timer::stop());
} else {
$result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
}
} catch (Exception $e) {
// PHPUnit_Util_Timer -> PHP_Timer support (see above)
if (class_exists('PHP_Timer')) {
$result->addFailure($this, $e, PHP_Timer::stop());
} else {
$result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
}
}
// PHPUnit_Util_Timer -> PHP_Timer support (see above)
if (class_exists('PHP_Timer')) {
$result->endTest($this, PHP_Timer::stop());
} else {
$result->endTest($this, PHPUnit_Util_Timer::stop());
}
$backend->recorder->record($this->test['test'], $r);
$this->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
return $result;
}
示例14: podlove_validate_image_cache
function podlove_validate_image_cache()
{
set_time_limit(5 * MINUTE_IN_SECONDS);
PHP_Timer::start();
$cache_files = glob(trailingslashit(Image::cache_dir()) . "*" . DIRECTORY_SEPARATOR . "*" . DIRECTORY_SEPARATOR . "cache.yml");
foreach ($cache_files as $cache_file) {
$cache = Yaml::parse(file_get_contents($cache_file));
$validator = new HttpHeaderValidator($cache['source'], $cache['etag'], $cache['last-modified']);
$validator->validate();
if ($validator->hasChanged()) {
wp_schedule_single_event(time(), 'podlove_refetch_cached_image', [$cache['source'], $cache['filename']]);
}
}
$time = PHP_Timer::stop();
\Podlove\Log::get()->addInfo(sprintf('Finished validating %d images in %s', count($cache_files), PHP_Timer::secondsToTimeString($time)));
}
示例15: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (\App::environment() === 'production') {
$this->error('This feature is not available on this server');
}
$process = new Process('apidoc -i ' . base_path('app/Http/Controllers') . ' -o ' . base_path('apidoc'));
$process->run();
if (!$process->isSuccessful()) {
$this->error('Impossible to generate doc');
$this->error($process->getErrorOutput());
$this->info('You need to install apidoc: (sudo) npm install apidoc -g');
return;
}
$this->info($process->getOutput());
$this->comment('Documentation generated in folder ' . base_path('doc'));
$this->comment(\PHP_Timer::resourceUsage());
}