当前位置: 首页>>代码示例>>C++>>正文


C++ Stopwatch::elapsedMilliseconds方法代码示例

本文整理汇总了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";
}
开发者ID:chipitsine,项目名称:ClickHouse,代码行数:32,代码来源:internal_iotop.cpp

示例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()));
    }
}
开发者ID:chipitsine,项目名称:ClickHouse,代码行数:39,代码来源:BackgroundSchedulePool.cpp


注:本文中的Stopwatch::elapsedMilliseconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。