#pragma once

#include <chrono>

typedef std::chrono::high_resolution_clock hrClock;
typedef std::chrono::duration<float, std::milli> fms;

class Timer {
  hrClock::time_point mStart;
  hrClock::duration mDuration;
  
public:
  Timer() {
    Reset();
  }
  
  void Reset() {
    mDuration = hrClock::duration::zero();
  }

  void Start() {
    mStart = hrClock::now();
  }

  void Stop() {
    hrClock::time_point end = hrClock::now();
    mDuration += end - mStart; 
  }
  
  float Elapsed(const bool reset=true) {
    float result = std::chrono::duration_cast<fms>(mDuration).count();
    if (reset)
      Reset();
    return result;
  }

};

