本文整理汇总了C++中Stopwatch::elapsedMilliseconds方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::elapsedMilliseconds方法的具体用法?C++ Stopwatch::elapsedMilliseconds怎么用?C++ Stopwatch::elapsedMilliseconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::elapsedMilliseconds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_perf
void test_perf()
{
::taskstats stat;
int tid = TaskStatsInfoGetter::getCurrentTID();
TaskStatsInfoGetter get_info;
rusage rusage;
constexpr size_t num_samples = 1000000;
{
Stopwatch watch;
for (size_t i = 0; i < num_samples; ++i)
getrusage(RUSAGE_THREAD, &rusage);
auto ms = watch.elapsedMilliseconds();
if (ms > 0)
std::cerr << "RUsage: " << double(ms) / num_samples << " ms per call, " << 1000 * num_samples / ms << " calls per second\n";
}
{
Stopwatch watch;
for (size_t i = 0; i < num_samples; ++i)
get_info.getStat(stat, tid);
auto ms = watch.elapsedMilliseconds();
if (ms > 0)
std::cerr << "Netlink: " << double(ms) / num_samples << " ms per call, " << 1000 * num_samples / ms << " calls per second\n";
}
std::cerr << stat << "\n";
}
示例2: lock_exec
void BackgroundSchedulePool::TaskInfo::execute()
{
Stopwatch watch;
CurrentMetrics::Increment metric_increment{CurrentMetrics::BackgroundSchedulePoolTask};
std::lock_guard lock_exec(exec_mutex);
{
std::lock_guard lock_schedule(schedule_mutex);
if (deactivated)
return;
scheduled = false;
executing = true;
}
function();
UInt64 milliseconds = watch.elapsedMilliseconds();
/// If the task is executed longer than specified time, it will be logged.
static const int32_t slow_execution_threshold_ms = 200;
if (milliseconds >= slow_execution_threshold_ms)
LOG_TRACE(&Logger::get(log_name), "Execution took " << milliseconds << " ms.");
{
std::lock_guard lock_schedule(schedule_mutex);
executing = false;
/// In case was scheduled while executing (including a scheduleAfter which expired) we schedule the task
/// on the queue. We don't call the function again here because this way all tasks
/// will have their chance to execute
if (scheduled)
pool.queue.enqueueNotification(new TaskNotification(shared_from_this()));
}
}