   FPS-counter-class wanted
  Hello everybody!Im searching for a good C++-Fps-Counter class but I cant find anyone. Does anybody have a good class or know where I could find something about that? I want to put a minimum of effort into this because I want to create other things. Thank you :)   
  Depends on what you want to count. Here's a class which, when provided with a timer object, and called once per frame, computes the average duration of a frame:template<typename Timer>class FPS_Counter{  typedef typename Timer::time_type time_type;  std::deque<time_type> times;  unsigned count;  time_type last;  time_type total;public:  FPS_Counter(unsigned count) :times(count), count(0), last(Timer::Now()), total() {}   void Frame()   {    time_type now = Timer::Now();    time_type delta = last - now;    last = now;    count = std::max(count + 1, times.size());    total += delta - times.front();    times.push_back(delta);    times.pop_front();  }  time_type Average() const  {    if (count == 0) return (Timer::Now() - last);    return total / count;  }};// Example timer based on std::clockstruct std_clock_timer{  typedef unsigned time_type;  static time_type Now() { return std::clock(); }};This provides a continuous measure (in that it doesn't vary too much over time when you get spikes, and is thus easier to read). Conversely, you can use a system to count the number of frames in a predefined period (for instance, a second) :template<typename Timer>class FPS_Counter{  typedef typename Timer::time_type time_type;  unsigned count;  unsigned last;  time_type next;    time_type delta;public:  FPS_Counter(time_type delta) :count(0), last(0), next(Timer::Now() + delta), delta(delta) {}  void Frame()   {    ++count;    time_type now = Timer::Now();    while (now > next)    {  next += delta; last = count; count = 0;    }  }    unsigned Frames() const  {    return last;  }};This will remain constant for the delta duration (for instance, one second) and then change to reflect the number of frames for that duration.   ;  Slight variation:class FPSCounter{  public:    FPSCounter(unsigned int restart = 1000, unsigned int time = 0)   : m_count(0), m_time_last(time), m_time_restart(restart),m_fps(0.0f) { }   void update(unsigned int ms)    {   unsigned int delta = ms - m_time_last; ++m_count; if(delta >= m_time_restart) {  m_fps = float(m_count*1000)/delta;  m_time_last = ms;  m_count = 0;   }    }   void set_restart(unsigned int ms)    {   m_time_restart = ms;    }   float fps() const    {   return m_fps;    } private:    unsigned int m_count;    unsigned int m_time_last,m_time_restart;    float m_fps;};On each update (and as second argument on constructor, if wanted), you must supply the current time in miliseconds (if not supplied on constructor, first fps result will be innacurate), so there is no need to attach a timer to it. As with ToohrVyk's second class, it has a predefined interval in which it will count and not update the measurement.   