本文整理汇总了PHP中Timer::getElapsed方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::getElapsed方法的具体用法?PHP Timer::getElapsed怎么用?PHP Timer::getElapsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::getElapsed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: open
/**
* Open a message store.
*
* @param string $identity The identity to open as an URI
*/
function open($identity)
{
$file = parse_url($identity, PHP_URL_HOST);
// Set up the paths and objects we need
$this->mbpath = config::get(FilesystemMailStorage::KEY_STORAGE_PATH, BASE_PATH . 'cache') . '/' . $file . '.xml';
$this->lockpath = config::get(FilesystemMailStorage::KEY_STORAGE_PATH, BASE_PATH . 'cache') . '/' . $file . '.lock';
$this->mbox = new DOMDocument('1.0');
// Primitive locking for the win :) This should be more than enough
// for whoever decides to use this. Will probably not be too good to
// the disk under heavy load.
$t = new Timer(true);
$to = config::get(FilesystemMailStorage::KEY_LOCK_TIMEOUT, FilesystemMailStorage::DEF_LOCK_TIMEOUT);
console::debugEx(LOG_DEBUG, __CLASS__, "Acquiring lock...");
while (file_exists($this->lockpath)) {
usleep(100000);
if ($t->getElapsed() > $to) {
throw new MailException("Timed out waiting for lock.");
}
}
unset($t);
$this->lock = fopen($this->lockpath, 'w');
// Check if the mailbox exists
if (file_exists($this->mbpath)) {
$this->mbox->load($this->mbpath);
console::debugEx(LOG_DEBUG, __CLASS__, "Loaded mailbox %s", $this->mbpath);
} else {
console::debugEx(LOG_DEBUG, __CLASS__, "Created new mailbox %s", $this->mbpath);
$this->mbox->appendChild($this->mbox->createElement('mailbox'));
}
}
示例2: run
function run()
{
$cases = Lunit::getCases();
$casedata = array();
// Enumerate the cases
foreach ($cases as $case) {
// Setup report structure
$casereport = array();
// Reflect the class to find methods and metadata
$r = new ReflectionClass($case);
$ml = $r->getMethods();
$skip = false;
$meta = LunitUtil::parseDoc($r->getDocComment());
if (!isset($meta['description'])) {
$meta['description'] = $case;
}
$meta['casename'] = $case;
if (isset($meta['extensions'])) {
$extn = explode(' ', $meta['extensions']);
foreach ($extn as $ext) {
if (!extension_loaded($ext)) {
$skip = true;
$skipmsg = "Need extension: " . $ext;
}
}
}
$casereport['meta'] = $meta;
// Callback if set
if ($this->statuscb) {
$this->statuscb->onCaseBegin($case, $meta);
}
if ($this->dblog) {
$this->dblog->onCaseBegin($case, $meta);
}
try {
if (!$skip) {
$tc = new $case($this);
}
foreach ($ml as $method) {
$methodname = $method->getName();
if ($method->isPublic() && substr($methodname, 0, 1) != '_') {
$methodreport = array();
$tmeta = LunitUtil::parseDoc($method->getDocComment());
if (!isset($tmeta['description'])) {
$tmeta['description'] = $methodname;
}
if (!isset($tmeta['repeat'])) {
$tmeta['repeat'] = 1;
}
// Save meta to method report
$methodreport['meta'] = $tmeta;
// Times to repeat the test
$repeat = intval($tmeta['repeat']);
// Callback if set, then create timer
if ($this->statuscb) {
$this->statuscb->onTestBegin($methodname, $tmeta);
}
if ($this->dblog) {
$this->dblog->onTestBegin($methodname, $meta);
}
$methodreport['skipped'] = false;
$tavg = null;
$tmax = null;
$tmin = null;
if (!$skip) {
$tm = new Timer();
try {
$telapsed = array();
$ttotal = 0;
for ($n = 0; $n < $repeat; $n++) {
$tm->start();
$tc->{$methodname}();
$tm->stop();
$telapsed[] = $tm->getElapsed() * 1000;
$ttotal += $tm->getElapsed() * 1000;
}
$ttot = math::sum($telapsed);
$tavg = math::average($telapsed);
$tmin = math::min($telapsed);
$tmax = math::max($telapsed);
$tdev = math::deviation($telapsed);
$methodreport['passed'] = true;
$methodreport['message'] = null;
if ($repeat > 1) {
// console::write('%6.1fms <%6.1fms> %6.1fms ', $tmin, $tavg, $tmax);
} else {
// console::write('%6.1fms ', $tmax);
}
if ($this->statuscb) {
$this->statuscb->onTestEnd(true, null);
}
if ($this->dblog) {
$this->dblog->onTestEnd(true, null);
}
} catch (LunitAssertionFailure $f) {
$tm->stop();
$methodreport['passed'] = false;
$methodreport['message'] = $f->getMessage();
if ($this->statuscb) {
$this->statuscb->onTestEnd(false, $f->getMessage());
//.........这里部分代码省略.........
示例3: run
/**
*
*/
static function run($class)
{
static $ic = 0;
$args = func_get_args();
$args = array_slice($args, 1);
Console::debugEx(LOG_EXTENDED, __CLASS__, "Inspecting environment module state:\n%s", ModuleManager::debug());
$ic++;
if (class_exists($class)) {
$rv = 0;
$apptimer = new Timer();
try {
$instance = new $class();
if (!$instance instanceof IApplication) {
console::warn("FATAL: Application is not instance of IApplication");
return RETURN_ERROR;
}
Console::debugEx(LOG_BASIC, __CLASS__, "Invoking application instance from %s.", $class);
$apptimer->start();
if (is_callable(array($instance, 'run'))) {
$rv = call_user_func_array(array($instance, 'run'), $args);
} else {
console::writeLn("Requested application class %s is not runnable.", $class);
}
$apptimer->stop();
unset($instance);
Console::debugEx(LOG_BASIC, __CLASS__, "Main method exited with code %d after %.2f seconds.", $rv, $apptimer->getElapsed());
} catch (Exception $e) {
throw $e;
}
$ic--;
if ($ic == 0) {
return $rv;
}
} else {
$ic--;
if ($ic == 0) {
Console::warn('FATAL: Application class %s not found!', $class);
exit(RETURN_ERROR);
} else {
Console::warn('Application class %s not found!', $class);
}
}
}
示例4: tickFunction
<?php
include "Timer.php";
/*declare(ticks = 1);
function tickFunction() {
}
register_tick_function("tickFunction");
*/
$running = true;
$iter = 0;
$timer = new Timer();
while ($running) {
$iter++;
$timer->update();
if ($iter >= 10000000) {
$running = false;
}
}
echo $timer->getElapsed() . PHP_EOL;
示例5: download
function download()
{
$this->createTables();
console::writeLn("Downloading updated sets...");
$e = str_repeat("", 70);
$ef = str_repeat("", 70) . str_repeat(" ", 70) . str_repeat("", 70);
$tot = count($this->data['update']);
$c = 0;
foreach ($this->data['update'] as $fn => $void) {
$this->total = array('max' => $tot, 'current' => $c++, 'percent' => 100 / $tot * $c);
$this->activity = "Downloading";
$this->activityobject = $fn;
$t = new Timer(true);
$dl = new HttpDownload($this->baseurl . $fn, base::appPath() . '/geocache/' . $fn, array('onprogress' => new Callback($this, 'onprogress')));
$td = $t->getElapsed();
$this->clearTask();
$flen = filesize(base::appPath() . '/geocache/' . $fn);
console::writeLn("%s downloaded (%d bytes in %.1f seconds, %.1f KB/s)", $fn, $flen, $td, $flen / 1024 / $td);
}
}