本文整理汇总了PHP中PHP_Timer::secondsToTimeString方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_Timer::secondsToTimeString方法的具体用法?PHP PHP_Timer::secondsToTimeString怎么用?PHP PHP_Timer::secondsToTimeString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_Timer
的用法示例。
在下文中一共展示了PHP_Timer::secondsToTimeString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: testSecondsToTimeString
/**
* @covers PHP_Timer::secondsToTimeString
*/
public function testSecondsToTimeString()
{
$this->assertEquals('0 seconds', PHP_Timer::secondsToTimeString(0));
$this->assertEquals('1 second', PHP_Timer::secondsToTimeString(1));
$this->assertEquals('2 seconds', PHP_Timer::secondsToTimeString(2));
$this->assertEquals('01:00', PHP_Timer::secondsToTimeString(60));
$this->assertEquals('01:01', PHP_Timer::secondsToTimeString(61));
$this->assertEquals('02:00', PHP_Timer::secondsToTimeString(120));
$this->assertEquals('02:01', PHP_Timer::secondsToTimeString(121));
$this->assertEquals('01:00:00', PHP_Timer::secondsToTimeString(3600));
$this->assertEquals('01:00:01', PHP_Timer::secondsToTimeString(3601));
}
示例3: 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)));
}
示例4: describe
<?php
use Peridot\Concurrency\Runner\StreamSelect\IO\JobInfo;
describe('JobInfo', function () {
beforeEach(function () {
$this->info = new JobInfo('/path/to/file.php');
$this->info->end = microtime(true);
});
describe('->getTimeElapsed()', function () {
it('should return a formatted time string', function () {
$formatted = PHP_Timer::secondsToTimeString($this->info->end - $this->info->start);
expect($this->info->getTimeElapsed())->to->equal($formatted);
});
});
});
示例5: callback
/**
* Invoked by pcntl_signal() when a SIGALRM occurs.
*/
public function callback()
{
throw new PHP_Invoker_TimeoutException(sprintf('Execution aborted after %s', PHP_Timer::secondsToTimeString($this->timeout)));
}
示例6: footer
/**
* Output result footer
*/
public function footer()
{
$this->output->write($this->color('success', sprintf("\n %d passing", $this->passing)));
$this->output->writeln(sprintf($this->color('muted', " (%s)"), \PHP_Timer::secondsToTimeString($this->getTime())));
if (!empty($this->errors)) {
$this->output->writeln($this->color('error', sprintf(" %d failing", count($this->errors))));
}
if ($this->pending) {
$this->output->writeln($this->color('pending', sprintf(" %d pending", $this->pending)));
}
$this->output->writeln("");
$errorCount = count($this->errors);
for ($i = 0; $i < $errorCount; $i++) {
list($test, $error) = $this->errors[$i];
$this->outputError($i + 1, $test, $error);
}
}
示例7: function
* User: Jiang Yu
* Date: 2015/06/30
* Time: 3:37 PM.
*/
use Worker\EndlessTasks;
require __DIR__ . '/../bootstrap.php';
$fireNotifications = function ($jsonArray) {
$requestFactory = new \Worker\Model\TaskFactory();
$tasks = [];
foreach ($jsonArray as $jsonString) {
$options = json_decode($jsonString, true);
if (!is_array($options)) {
continue;
}
$tasks[] = $requestFactory->create($options[CURLOPT_URL], $options);
}
PHP_Timer::start();
$worker = new \Worker\CurlWorker();
$worker->addTasks($tasks);
$worker->run();
$delta = PHP_Timer::stop();
echo PHP_Timer::resourceUsage() . ' fire notif cost: ' . PHP_Timer::secondsToTimeString($delta) . PHP_EOL;
};
$facebookOptions = \Application\Facade::getInstance()->getFBGatewayOptions();
dump($facebookOptions);
$taskGenerator = new EndlessTasks($facebookOptions['queueLocation']);
$bufferedNotifications = $taskGenerator->get();
/** @var string[] $tasks */
foreach ($bufferedNotifications as $tasks) {
call_user_func($fireNotifications, $tasks);
}
示例8: Test
}
$this->exception = $exception;
$this->emitter->emit('test.passed', [new Test('passing test', function () {
})]);
$this->emitter->emit('test.failed', [new Test('failing test', function () {
}), $this->exception]);
$this->emitter->emit('test.pending', [new Test('pending test', function () {
})]);
$this->footer = $this->reporter->footer();
$this->contents = $this->output->fetch();
});
it('should output success text', function () {
assert(strstr($this->contents, '1 passing') !== false, 'should contain passing text');
});
it('should output time', function () {
$time = PHP_Timer::secondsToTimeString($this->reporter->getTime());
assert(strstr($this->contents, $time) !== false, 'should contain time text');
});
it('should output failure text', function () {
assert(strstr($this->contents, '1 failing') !== false, 'should contain failure text');
});
it('should output pending count', function () {
assert(strstr($this->contents, '1 pending') !== false, 'should contain pending text');
});
it('should display exception stacks and messages', function () {
$expectedExceptionMessage = " ooops" . PHP_EOL . " nextline";
assert(strstr($this->contents, $expectedExceptionMessage) !== false, "should include exception message");
$trace = preg_replace('/^#/m', " #", $this->exception->getTraceAsString());
assert(strstr($this->contents, $trace) !== false, "should include exception stack");
});
});
示例9:
<hr>
<small>
<?php
if (isset($hasControllerActionTime)) {
?>
<div>Controller Action Execution Time: <?php
echo PHP_Timer::secondsToTimeString(PHP_Timer::stop());
?>
</div>
<?php
}
?>
<div>Execution Time: <?php
echo PHP_Timer::timeSinceStartOfRequest();
?>
</div>
<?php
if (isset($bootstrapTime)) {
?>
<div>Application Bootstrap Time: <?php
echo $bootstrapTime;
?>
</div>
<?php
}
?>
<?php
示例10: foreach
$stepGenerator = WorkRoundGenerator::generate($now, $quitTimestamp, $interval, false);
foreach ($stepGenerator as $timestamp) {
$msg = $myself . ': ' . date('c', $timestamp) . ' run with ts ' . date('c', $timestamp);
appendLog($msg);
$date = $specifiedDate ? $specifiedDate : date('Y-m-d');
$groupedUidList = $installUidProvider->generate($date, function ($shardId, $userCount, $delta) {
if ($userCount === 0) {
return;
}
appendLog(sprintf('%s install(%d) cost %s', $shardId, $userCount, PHP_Timer::secondsToTimeString($delta)));
});
$queue->push($groupedUidList);
$deltaList = $installUidProvider->getDeltaList();
$totalCount = 0;
foreach ($groupedUidList as $shardId => $shardUidList) {
$shardCount = count($shardUidList);
if ($shardCount === 0) {
continue;
}
$totalCount += $shardCount;
}
appendLog(sprintf('%s: %s found %d install user, cost %s', $myself, date('c'), $totalCount, PHP_Timer::secondsToTimeString(array_sum($deltaList))));
$logFile = call_user_func($logFileGetter, $gameVersion, $date);
file_put_contents($logFile, date('c') . ' have ' . $totalCount . PHP_EOL . print_r($groupedUidList, true));
if ($specifiedDate) {
dump(date('c'));
dump($groupedUidList);
dump($myself . ': quit');
break;
}
}
示例11: onConcurrentRunnerEnd
/**
* Output test stats. If any errors were written to stderr at any point, then
* they will be dumped here.
*
* @param array $errors
* @return void
*/
public function onConcurrentRunnerEnd($errors)
{
$this->output->writeln(sprintf(' Run time: %s', \PHP_Timer::secondsToTimeString($this->getTime())));
$errorCount = count($errors);
if (!$errorCount) {
return;
}
$labels = ['was', 'error'];
if ($errorCount > 1) {
$labels = ['were', 'errors'];
}
$this->output->writeln('');
$this->output->writeln($this->color('error', sprintf('There %s %d %s:', $labels[0], $errorCount, $labels[1])));
$this->outputErrors($errors);
}
示例12: findDeAuthorizedUser
/**
* @param Platform $platform
* @param DeAuthorizedUserQuery $query
*
* @return array
* @throws Exception
*/
protected function findDeAuthorizedUser(Platform $platform, DeAuthorizedUserQuery $query)
{
$resultSet = [];
$shardList = $platform->getMySQLShards();
foreach ($shardList as $shardConfig) {
$dbName = $shardConfig['database'];
appendLog('on database ' . $dbName);
PHP_Timer::start();
$snsidList = $this->onShard($shardConfig, $query);
$delta = PHP_Timer::stop();
appendLog('cost on database ' . $dbName . ': ' . PHP_Timer::secondsToTimeString($delta));
dump(sprintf('Memory: %4.2fMb', memory_get_peak_usage(true) / 1048576));
$resultSet = array_merge($resultSet, $snsidList);
}
return $resultSet;
}
示例13: getTimeElapsed
/**
* The time elapsed on the job as a formatted time
* string.
*
* @return string
*/
public function getTimeElapsed()
{
return \PHP_Timer::secondsToTimeString($this->end - $this->start);
}
示例14: assert
} else {
assert(isset($options['gv']), 'game version not defined');
$gameVersion = trim($options['gv']);
}
$esHost = isset($options['es']) ? $options['es'] : '52.19.73.190';
assert(isset($options['uid']), 'uid not defined');
$uid = trim($options['uid']);
$msg = sprintf('game version: %s, ES host: %s, uid: %s', $gameVersion, $esHost, $uid);
$verbose && dump($msg);
$provider = new UserDetailProvider($gameVersion, PdoFactory::makePool($gameVersion));
$groupedUserList = array_filter($provider->find([$uid]));
if ($verbose) {
dump(__FILE__);
dump($groupedUserList);
}
$indexer = IndexerFactory::make($esHost, $gameVersion);
foreach ($groupedUserList as $shardId => $shardUserList) {
$delta = $indexer->batchUpdate($shardUserList);
$batchResult = $indexer->getBatchResult();
dump(__FILE__);
array_map(function ($errorString) {
$decoded = json_decode($errorString, true);
if (is_array($decoded)) {
dump($decoded);
} else {
dump($errorString);
}
}, $batchResult);
// dump($indexer->getLastRoundData());
dump('cost ' . PHP_Timer::secondsToTimeString($delta[0]));
}
示例15: explode
$arr = explode('/', parse_url($url, PHP_URL_PATH));
return (string) $arr[3];
}
$snsidList = ['100001349218797', '675097095878591', '675097095878592', '675097095878593', '675097095878594'];
$taskFactory = new \Worker\Model\TaskFactory();
$tasks = array_map(function ($snsid) use($taskFactory) {
$url = sprintf('http://52.19.73.190:9200/farm/user:tw/%s/_update', $snsid);
$postData = sprintf('{"doc":{"status":"%d"}}', time());
return $taskFactory->create($url, [CURLOPT_URL => $url, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $postData, CURLOPT_RETURNTRANSFER => 1]);
}, $snsidList);
//dump($tasks);
PHP_Timer::start();
$curlWorker = new \Worker\CurlWorker(new \Worker\Queue\HttpTracer());
$curlWorker->addTasks($tasks);
$responseList = [];
$trace = $curlWorker->run($responseList, function () {
echo microtime(true) . ' got response' . PHP_EOL;
});
$taskWallTime = PHP_Timer::stop();
array_walk($responseList, function (array $response) {
dump(['url' => $response['url'], 'http_code' => $response['http_code'], 'content' => $response['content']]);
});
$httpCost = 0;
array_walk($trace, function (\Worker\Queue\HttpTracer $httpTracer, $url) use(&$httpCost) {
$httpCost += $httpTracer->getElapsedTime();
dump(parseSnsid($url) . ' => ' . $httpTracer);
});
dump('time cost on http: ' . PHP_Timer::secondsToTimeString($httpCost));
dump('wall time on http: ' . PHP_Timer::secondsToTimeString($taskWallTime));
dump('Run time: ' . PHP_Timer::timeSinceStartOfRequest());
dump(sprintf('Memory: %4.2fMb', memory_get_peak_usage(true) / 1048576));