Skip to content

Commit

Permalink
Add time
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-42 committed Oct 28, 2020
1 parent 7fd1e99 commit a793898
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libraries/http_server/http_server/timer.hh
@@ -0,0 +1,29 @@
#pragma once

#include <chrono>

namespace li
{

class timer {
public:
inline void start() { start_ = std::chrono::high_resolution_clock::now(); }
inline void end() { end_ = std::chrono::high_resolution_clock::now(); }

inline unsigned long us() const {
return std::chrono::duration_cast<std::chrono::microseconds>(end_ - start_).count();
}

inline unsigned long ms() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(end_ - start_).count();
}

inline unsigned long ns() const {
return std::chrono::duration_cast<std::chrono::nanoseconds>(end_ - start_).count();
}

private:
std::chrono::time_point<std::chrono::high_resolution_clock> start_, end_;
};

}

0 comments on commit a793898

Please sign in to comment.