统计帧率的几种方法


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



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

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

转载于:https://www.cnblogs.com/18fanna/p/3881594.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值