⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.hh

📁 Develop Zigbee network real-time Os
💻 HH
字号:
/* * timer: timing utilities * Copyright(c) 2004-2005 by wave++ "Yuri D'Elia" <wavexx@users.sf.net> * Distributed under GNU LGPL WITHOUT ANY WARRANTY. */#ifndef timer_hh#define timer_hh// c system headers#include <sys/time.h>// Averaging stop-watch timer (with variable-bound precision)class ATimer{  double delta;  double cum;  double le;  double ini;  double last;  unsigned long sc;  double now()  {    timeval n;    gettimeofday(&n, 0);    return (static_cast<double>(n.tv_sec) +	.000001 * static_cast<double>(n.tv_usec));  }public:  explicit  ATimer(double delta)  : delta(delta), cum(0), le(0), last(0), sc(0)  {    ini = now();  }  void  start()  {    le = now();  }  void  stop()  {    double n = now();    cum += n - le;    le = n;    ++sc;  }  double  avg()  {    double n = now();    if((n - ini) >= delta)    {      last = cum / (sc? sc: 1);      ini = n;      cum = 0;      sc = 0;    }    return last;  }};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -