<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0047)http://www.cc.gatech.edu/ccg/people/david/fps.h -->
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY><XMP>#ifndef _FPS_H_
#define _FPS_H_
/*********************************************************************
* Instructions
*
* (1) Create an FPS object
* (2) Call addFrame() for each new frame
* (i.e. each occurence of event you're tracking)
* (3) Call display(ms) to display the current fps every
* [ms] milliseconds
* (3a) or, call display(ms, msg) to do the same with a custom message
* (3b) or, call getFps(ms) to get the fps directly
* if the fps value was calculated more than ms milliseconds ago
* it will be recomputed -- no paramter => 500ms
* (4) optionally, you can call reset() at any time to reset the tracker
*
* example:
* ...
* // perform possibly slow operation and display fps each second
* FPS fps;
* while(1){
* performSlowOperation();
* fps.addFrame();
* fps.display(1000);
* }
* ...
*********************************************************************/
#ifndef WIN32
#include <sys/time.h>
#endif
class FPS{
protected:
#ifdef WIN32
int last, cur;
#else
struct timeval last, cur;
#endif
long n;
float fps;
public:
void addFrame(){
n++;
}
int display(long minMS, char *msg){
if (ready(minMS)){
printf("%s%0.3f\n", msg, fps);
return 1;
}
return 0;
}
int ready(long minMS){
long dm; // difference in seconds, micro, and milli
#ifdef WIN32
cur = GetTickCount();
dm = cur - last;
#else
long ds, du;
gettimeofday(&cur, NULL);
ds = cur.tv_sec - last.tv_sec;
du = 1000000*ds - last.tv_usec + cur.tv_usec;
dm = du / 1000;
#endif
if (dm>=minMS){
fps = 1000.0f * (float)n / (float)dm;
n = 0;
#ifdef WIN32
last = cur;
#else
last.tv_sec = cur.tv_sec;
last.tv_usec = cur.tv_usec;
#endif
return 1;
}
return 0;
}
float getFps(int v = 500){
ready(v);
return fps;
}
int display(long minMS){
return display(minMS, "fps: ");
}
void reset(){
n = 0;
fps = 0.0f;
#ifdef WIN32
last = GetTickCount();
#else
gettimeofday(&last, NULL);
#endif
}
FPS(){
reset();
}
};
#endif
</XMP></BODY></HTML>
stbomei
- 粉丝: 44
- 资源: 1180
最新资源
- 基于K-means算法的光伏曲线聚类研究 MATLAB 代码研究大量随机场景下光伏序列聚类与削减问题,首先,生成大量光伏随机场景,其次,采用的是较为基础的K-means算法,经过matlab求解后,代
- 三菱Fx3u程序,自动检测包装机 该程序六个电机,plc本体脉冲控制3个轴,3个1pg控制 程序内包括伺服定位,手自动切,功能快的使用,可作为模板程序,很适合新手
- 西门子新一代伺服驱动系统SINAMICS S200 PN驱动器连接的电机均为绝对值编码器类型,在EPOS控制模式下有主动回零、被动回零、设置参考点及绝对值编码器校准几种回参考点方式
- Linux下使用v4l2-ctl命令检查摄像头及相关音视频设备硬件特性
- sqlserver-trigger-socket通信
- 文件下载,无特殊意义,无需纠结
- 法奥Linux下的VisualCode配置C++SDK
- 2022级嵌入式Linux期末课程设计-选题参考.rar
- 基于STM32F103的多摩川绝对值磁编码器通讯方案 包含:原理图,PCB,源码,多摩川协议手册
- 成都链家二手房.zip
- arm-linux-gcc-4.5.1-v6-vfp-20120301.7z
- S7-1200 PLC 连接 SINAMICS S200 PN伺服驱动系统
- 数据结构期末作业:基于Python的zzu校园导航.zip
- 51单片机数控可调稳压电源proteus仿真,可调范围为3-24V,可以矩阵键盘直接设置输出电压,也可以步进0.1V设置输出电压,1602lcd显示设置值与实际输出值
- DLLDirectX文件修复工具
- BC文件比较工具.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈