本文整理汇总了PHP中Timer::elapsed方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::elapsed方法的具体用法?PHP Timer::elapsed怎么用?PHP Timer::elapsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::elapsed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
public function query($sql)
{
if ($this->log !== false) {
$backtrace = debug_backtrace();
if (isset($backtrace[1])) {
$this->log->write($backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . ': Sending SQL: ' . $sql, XBM_LOG_DEBUG);
} else {
$this->log->write('Sending SQL: ' . $sql, XBM_LOG_DEBUG);
}
$timer = new Timer();
}
$res = parent::query($sql);
if ($this->log !== false) {
$elapsed = $timer->elapsed();
if (isset($backtrace[1])) {
$this->log->write($backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . ': Query took ' . $elapsed, XBM_LOG_DEBUG);
} else {
$this->log->write('Query took ' . $elapsed, XBM_LOG_DEBUG);
}
}
return $res;
}
示例2: createTables
public static function createTables(\PDO $pdo_db, string $db_prefix, string $dbtype)
{
$create_table_results = array();
$i = 0;
define('PDO_SUCCESS', (string) '00000');
// PDO gives an error code of string 00000 if successful. Not extremely helpful.
$schema_files = new \DirectoryIterator('schema/' . $dbtype);
foreach ($schema_files as $schema_filename) {
$table_timer = new Timer();
$table_timer->start();
// Start benchmarking
if ($schema_filename->isFile() && $schema_filename->getExtension() == 'sql') {
// Since we are using strict types, the Directory Iterator returns an object, and we want a string to pass to mb_substr.
$simple_filename = (string) $schema_filename->getFilename();
// Routine to handle persistent database tables. If a SQL schema file starts with persist-, then it is a persistent table
$persist_file = mb_substr($simple_filename, 0, 8) === 'persist-';
if ($persist_file) {
$tablename = mb_substr($simple_filename, 8, -4);
} else {
$tablename = mb_substr($simple_filename, 0, -4);
}
// Slurp the SQL call from schema, and turn it into an SQL string
$sql_query = file_get_contents('schema/' . $dbtype . '/' . $schema_filename);
// Replace the default prefix (tki_) with the chosen table prefix from the game
$sql_query = preg_replace('/tki_/', $db_prefix, $sql_query);
// Remove comments from SQL
$RXSQLComments = '@(--[^\\r\\n]*)|(\\#[^\\r\\n]*)|(/\\*[\\w\\W]*?(?=\\*/)\\*/)@ms';
$sql_query = $sql_query == '' ? '' : preg_replace($RXSQLComments, '', $sql_query);
// FUTURE: Test handling invalid SQL to ensure it hits the error logger below AND the visible output during running
$sth = $pdo_db->prepare($sql_query);
$sth->execute();
if ($pdo_db->errorCode() !== PDO_SUCCESS) {
$errorinfo = $pdo_db->errorInfo();
$create_table_results[$i]['result'] = $errorinfo[1] . ': ' . $errorinfo[2];
} else {
$create_table_results[$i]['result'] = true;
}
// Db::logDbErrors($pdo_db, $execute_res, __LINE__, __FILE__); // Triggers errors because there is no DB
$create_table_results[$i]['name'] = $db_prefix . $tablename;
$table_timer->stop();
$create_table_results[$i]['time'] = $table_timer->elapsed();
$i++;
}
}
return $create_table_results;
}
示例3: Timer
<?php
require_once "Timer.php";
$timer = new Timer();
?>
<HTML>
<HEAD>
<TITLE>Test Page (elapsed time: <?php
echo $timer->elapsed();
?>
seconds)</TITLE>
</HEAD>
<BODY>
This is a simple test page.
Elapsed time: <?php
echo $timer->elapsed();
?>
seconds.
</BODY>
</HTML>
<!-- Final elapsed time: <?php
echo $timer->elapsed();
?>
seconds. -->
示例4: test
function test($obj, $func)
{
global $count;
$timer = new Timer();
$timer->start();
for ($i = 0; $i < $count; $i++) {
$obj->{$func}(rand(0, $count * 10));
}
return round($timer->elapsed(), 6);
}