mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-09 13:10:25 +00:00
56 lines
876 B
C++
56 lines
876 B
C++
#ifndef LLARP_STOPWATCH_HPP
|
|
#define LLARP_STOPWATCH_HPP
|
|
|
|
#include <absl/types/optional.h>
|
|
#include <absl/time/clock.h>
|
|
|
|
namespace llarp
|
|
{
|
|
namespace util
|
|
{
|
|
class Stopwatch
|
|
{
|
|
absl::optional< absl::Time > m_start;
|
|
absl::optional< absl::Time > m_stop;
|
|
|
|
public:
|
|
Stopwatch()
|
|
{
|
|
}
|
|
|
|
void
|
|
start()
|
|
{
|
|
assert(!m_start);
|
|
assert(!m_stop);
|
|
m_start.emplace(absl::Now());
|
|
}
|
|
|
|
void
|
|
stop()
|
|
{
|
|
assert(m_start);
|
|
assert(!m_stop);
|
|
m_stop.emplace(absl::Now());
|
|
}
|
|
|
|
bool
|
|
done() const
|
|
{
|
|
return m_start && m_stop;
|
|
}
|
|
|
|
absl::Duration
|
|
time() const
|
|
{
|
|
assert(m_start);
|
|
assert(m_stop);
|
|
return m_stop.value() - m_start.value();
|
|
}
|
|
};
|
|
|
|
} // namespace util
|
|
} // namespace llarp
|
|
|
|
#endif
|