本文整理汇总了C++中PerformanceTimer::elapsed方法的典型用法代码示例。如果您正苦于以下问题:C++ PerformanceTimer::elapsed方法的具体用法?C++ PerformanceTimer::elapsed怎么用?C++ PerformanceTimer::elapsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PerformanceTimer
的用法示例。
在下文中一共展示了PerformanceTimer::elapsed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNetworkTimeUs
// static
qint64 EngineNetworkStream::getNetworkTimeUs() {
// This matches the GPL2 implementation found in
// https://github.com/codders/libshout/blob/a17fb84671d3732317b0353d7281cc47e2df6cf6/src/timing/timing.c
// Instead of ms resolution we use a us resolution to allow low latency settings
// will overflow > 200,000 years
#ifdef __WINDOWS__
FILETIME ft;
qint64 t;
// no GetSystemTimePreciseAsFileTime available, fall
// back to GetSystemTimeAsFileTime. This happens before
// Windows 8 and Windows Server 2012
// GetSystemTime?AsFileTime is NTP adjusted
// QueryPerformanceCounter depends on the CPU crystal
if(s_pfpgGetSystemTimeFn) {
s_pfpgGetSystemTimeFn(&ft);
return ((qint64)ft.dwHighDateTime << 32 | ft.dwLowDateTime) / 10;
} else {
static qint64 oldNow = 0;
static qint64 incCount = 0;
static PerformanceTimer timerSinceInc;
GetSystemTimeAsFileTime(&ft);
qint64 now = ((qint64)ft.dwHighDateTime << 32 | ft.dwLowDateTime) / 10;
if (now == oldNow) {
// timer was not incremented since last call (< 15 ms)
// Add time since last function call after last increment
// This reduces the jitter < one call cycle which is sufficient
LARGE_INTEGER li;
now += timerSinceInc.elapsed().toIntegerMicros();
} else {
// timer was incremented
LARGE_INTEGER li;
timerSinceInc.start();
oldNow = now;
}
return now;
}
#elif defined(__APPLE__)
// clock_gettime is not implemented on OSX
// gettimeofday can go backward due to NTP adjusting
// this will work here, because we take the stream start time for reference
struct timeval mtv;
gettimeofday(&mtv, NULL);
return (qint64)(mtv.tv_sec) * 1000000 + mtv.tv_usec;
#else
// CLOCK_MONOTONIC is NTP adjusted
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000000LL + ts.tv_nsec / 1000;
#endif
}
示例2: while
QList<AnalysisDao::AnalysisInfo> AnalysisDao::loadAnalysesFromQuery(TrackId trackId, QSqlQuery* query) {
QList<AnalysisDao::AnalysisInfo> analyses;
PerformanceTimer time;
time.start();
if (!query->exec()) {
LOG_FAILED_QUERY(*query) << "couldn't get analyses for track" << trackId;
return analyses;
}
int bytes = 0;
QSqlRecord queryRecord = query->record();
const int idColumn = queryRecord.indexOf("id");
const int typeColumn = queryRecord.indexOf("type");
const int descriptionColumn = queryRecord.indexOf("description");
const int versionColumn = queryRecord.indexOf("version");
const int dataChecksumColumn = queryRecord.indexOf("data_checksum");
while (query->next()) {
AnalysisDao::AnalysisInfo info;
info.analysisId = query->value(idColumn).toInt();
info.trackId = trackId;
info.type = static_cast<AnalysisType>(query->value(typeColumn).toInt());
info.description = query->value(descriptionColumn).toString();
info.version = query->value(versionColumn).toString();
int checksum = query->value(dataChecksumColumn).toInt();
QString dataPath = getAnalysisStoragePath().absoluteFilePath(
QString::number(info.analysisId));
QByteArray compressedData = loadDataFromFile(dataPath);
int file_checksum = qChecksum(compressedData.constData(),
compressedData.length());
if (checksum != file_checksum) {
qDebug() << "WARNING: Corrupt analysis loaded from" << dataPath
<< "length" << compressedData.length();
continue;
}
info.data = qUncompress(compressedData);
bytes += info.data.length();
analyses.append(info);
}
qDebug() << "AnalysisDAO fetched" << analyses.size() << "analyses,"
<< bytes << "bytes for track"
<< trackId << "in" << time.elapsed().debugMillisWithUnit();
return analyses;
}
示例3: updateIndexWithQuery
bool BaseTrackCache::updateIndexWithQuery(const QString& queryString) {
PerformanceTimer timer;
timer.start();
if (sDebug) {
qDebug() << "updateIndexWithQuery issuing query:" << queryString;
}
QSqlQuery query(m_database);
// This causes a memory savings since QSqlCachedResult (what QtSQLite uses)
// won't allocate a giant in-memory table that we won't use at all.
query.setForwardOnly(true); // performance improvement?
query.prepare(queryString);
if (!query.exec()) {
LOG_FAILED_QUERY(query);
return false;
}
int numColumns = columnCount();
int idColumn = query.record().indexOf(m_idColumn);
while (query.next()) {
TrackId trackId(query.value(idColumn));
//m_trackInfo[id] will insert a QVector<QVariant> into the
//m_trackInfo HashTable with the key "id"
QVector<QVariant>& record = m_trackInfo[trackId];
record.resize(numColumns);
for (int i = 0; i < numColumns; ++i) {
record[i] = query.value(i);
}
}
qDebug() << this << "updateIndexWithQuery took" << timer.elapsed().debugMillisWithUnit();
return true;
}
示例4: saveAnalysis
bool AnalysisDao::saveAnalysis(AnalysisDao::AnalysisInfo* info) {
if (!m_db.isOpen() || info == NULL) {
return false;
}
if (!info->trackId.isValid()) {
qDebug() << "Can't save analysis since trackId is invalid.";
return false;
}
PerformanceTimer time;
time.start();
QByteArray compressedData = qCompress(info->data, kCompressionLevel);
int checksum = qChecksum(compressedData.constData(),
compressedData.length());
QSqlQuery query(m_db);
if (info->analysisId == -1) {
query.prepare(QString(
"INSERT INTO %1 (track_id, type, description, version, data_checksum) "
"VALUES (:trackId,:type,:description,:version,:data_checksum)")
.arg(s_analysisTableName));
QByteArray waveformBytes;
query.bindValue(":trackId", info->trackId.toVariant());
query.bindValue(":type", info->type);
query.bindValue(":description", info->description);
query.bindValue(":version", info->version);
query.bindValue(":data_checksum", checksum);
if (!query.exec()) {
LOG_FAILED_QUERY(query) << "couldn't save new analysis";
return false;
}
info->analysisId = query.lastInsertId().toInt();
} else {
query.prepare(QString(
"UPDATE %1 SET "
"track_id = :trackId,"
"type = :type,"
"description = :description,"
"version = :version,"
"data_checksum = :data_checksum "
"WHERE id = :analysisId").arg(s_analysisTableName));
query.bindValue(":analysisId", info->analysisId);
query.bindValue(":trackId", info->trackId.toVariant());
query.bindValue(":type", info->type);
query.bindValue(":description", info->description);
query.bindValue(":version", info->version);
query.bindValue(":data_checksum", checksum);
if (!query.exec()) {
LOG_FAILED_QUERY(query) << "couldn't update existing analysis";
return false;
}
}
QString dataPath = getAnalysisStoragePath().absoluteFilePath(
QString::number(info->analysisId));
if (!saveDataToFile(dataPath, compressedData)) {
qDebug() << "WARNING: Couldn't save analysis data to file" << dataPath;
return false;
}
qDebug() << "AnalysisDAO saved analysis" << info->analysisId
<< QString("%1 (%2 compressed)").arg(QString::number(info->data.length()),
QString::number(compressedData.length()))
<< "bytes for track"
<< info->trackId << "in" << time.elapsed().debugMillisWithUnit();
return true;
}
示例5: select
//.........这里部分代码省略.........
// won't allocate a giant in-memory table that we won't use at all.
query.setForwardOnly(true);
query.prepare(queryString);
if (!query.exec()) {
LOG_FAILED_QUERY(query);
return;
}
// Remove all the rows from the table. We wait to do this until after the
// table query has succeeded. See Bug #1090888.
// TODO(rryan) we could edit the table in place instead of clearing it?
if (!m_rowInfo.isEmpty()) {
beginRemoveRows(QModelIndex(), 0, m_rowInfo.size() - 1);
m_rowInfo.clear();
m_trackIdToRows.clear();
endRemoveRows();
}
// sqlite does not set size and m_rowInfo was just cleared
//if (sDebug) {
// qDebug() << "Rows returned" << rows << m_rowInfo.size();
//}
QVector<RowInfo> rowInfo;
QSet<TrackId> trackIds;
while (query.next()) {
TrackId trackId(query.value(kIdColumn));
trackIds.insert(trackId);
RowInfo thisRowInfo;
thisRowInfo.trackId = trackId;
// save rows where this currently track id is located
thisRowInfo.order = rowInfo.size();
// Get all the table columns and store them in the hash for this
// row-info section.
thisRowInfo.metadata.reserve(m_tableColumns.size());
for (int i = 0; i < m_tableColumns.size(); ++i) {
thisRowInfo.metadata << query.value(i);
}
rowInfo.push_back(thisRowInfo);
}
if (sDebug) {
qDebug() << "Rows actually received:" << rowInfo.size();
}
if (m_trackSource) {
m_trackSource->filterAndSort(trackIds, m_currentSearch,
m_currentSearchFilter,
m_trackSourceOrderBy,
m_trackSourceSortColumn,
m_trackSourceSortOrder,
&m_trackSortOrder);
// Re-sort the track IDs since filterAndSort can change their order or mark
// them for removal (by setting their row to -1).
for (QVector<RowInfo>::iterator it = rowInfo.begin();
it != rowInfo.end(); ++it) {
// If the sort is not a track column then we will sort only to
// separate removed tracks (order == -1) from present tracks (order ==
// 0). Otherwise we sort by the order that filterAndSort returned to us.
if (m_trackSourceOrderBy.isEmpty()) {
it->order = m_trackSortOrder.contains(it->trackId) ? 0 : -1;
} else {
it->order = m_trackSortOrder.value(it->trackId, -1);
}
}
}
// RowInfo::operator< sorts by the order field, except -1 is placed at the
// end so we can easily slice off rows that are no longer present. Stable
// sort is necessary because the tracks may be in pre-sorted order so we
// should not disturb that if we are only removing tracks.
qStableSort(rowInfo.begin(), rowInfo.end());
m_trackIdToRows.clear();
for (int i = 0; i < rowInfo.size(); ++i) {
const RowInfo& row = rowInfo[i];
if (row.order == -1) {
// We've reached the end of valid rows. Resize rowInfo to cut off
// this and all further elements.
rowInfo.resize(i);
break;
}
QLinkedList<int>& rows = m_trackIdToRows[row.trackId];
rows.push_back(i);
}
// We're done! Issue the update signals and replace the master maps.
if (!rowInfo.isEmpty()) {
beginInsertRows(QModelIndex(), 0, rowInfo.size() - 1);
m_rowInfo = rowInfo;
endInsertRows();
}
qDebug() << this << "select() took" << time.elapsed().formatMillisWithUnit()
<< rowInfo.size();
}