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 清空;



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

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

  • 相关阅读:
    设置cookie,读取cookie案例
    npm常用命令及版本号浅析
    nrm安装与使用
    ES6解构赋值
    nodemon 基本配置与使用
    nodejs开发辅助工具nodemon
    Node自动重启工具 nodemon
    深入浅出Object.defineProperty()
    js原生缓慢返回顶部函数封装
    The linux command 之权限
  • 原文地址:https://www.cnblogs.com/18fanna/p/3881594.html
Copyright © 2011-2022 走看看