zoukankan      html  css  js  c++  java
  • 统计帧率的几种方法


    class
    CFpsSta {public: time_t m_start_time; bool flag; float m_count; float m_last_fps; CFpsSta(); void checkFps(); };
    void CFpsSta::checkFps()
    {
        time_t current_time=time(NULL);
        double diff=difftime(current_time,m_start_time);
        
        if (diff>=5 && !flag)
        {
            m_last_fps=m_count/diff;
            cout<<m_last_fps<<endl;
            flag=true;
            m_start_time=current_time;
            m_count=0;
        }
        if ( flag)
        {
            flag=false;
        }
    
        
    }


    每5秒计算一次平均帧率,并清空数值,重新计数;下一次调用时,重设flag; 其中m_count在绘制函数后++。

     
    第二种

    class CFpsSta2
    {public:
    
    queue<time_t> counts;
    
    CFpsSta2();
    void checkFps();
    };
    void CFpsSta2::checkFps()
    {
        time_t current_time=time(NULL);
        counts.push(current_time);
    
        double diff=current_time-counts.front();
        //cout<<diff<<endl;
        if(diff>=1)
        {
            cout<<counts.size()/diff<<endl;
            while(!counts.empty())
                counts.pop();    
        }
    }

    对绘制时间入队列,每次检测到队列首尾时间差大于1秒时 输入size 清空;



      两种方式分别是对帧率计算中的帧数和时间加以控制,第一种是以帧数为主,时间为辅;第二种主要观测时间。

     其他指标在实现时,如果有多个因素,也会有多个计算方法,选择合适的。

  • 相关阅读:
    smarty中ifelse、foreach以及获取数组中键值名的一个实例
    smarty逻辑运算符
    python strip()函数 介绍
    (转)论python工厂函数与内建函数
    数据结构哈希表(转)
    哈希表算法的编写
    哈希表(转)
    平衡二叉树的旋转操作
    并查集详解(转)
    Java数组技巧攻略
  • 原文地址:https://www.cnblogs.com/18fanna/p/3881594.html
Copyright © 2011-2022 走看看