• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef UTIL_TICKS_H_
6 #define UTIL_TICKS_H_
7 
8 #include <stdint.h>
9 
10 using Ticks = uint64_t;
11 
12 class TickDelta {
13  public:
TickDelta(uint64_t delta)14   explicit TickDelta(uint64_t delta) : delta_(delta) {}
15 
InSecondsF()16   double InSecondsF() const { return delta_ / 1000000000.0; }
InMillisecondsF()17   double InMillisecondsF() const { return delta_ / 1000000.0; }
InMicrosecondsF()18   double InMicrosecondsF() const { return delta_ / 1000.0; }
InNanosecondsF()19   double InNanosecondsF() const { return delta_; }
20 
InSeconds()21   uint64_t InSeconds() const { return delta_ / 1000000000; }
InMilliseconds()22   uint64_t InMilliseconds() const { return delta_ / 1000000; }
InMicroseconds()23   uint64_t InMicroseconds() const { return delta_ / 1000; }
InNanoseconds()24   uint64_t InNanoseconds() const { return delta_; }
25 
raw()26   uint64_t raw() const { return delta_; }
27 
28  private:
29   uint64_t delta_;
30 };
31 
32 Ticks TicksNow();
33 
34 TickDelta TicksDelta(Ticks new_ticks, Ticks old_ticks);
35 
36 class ElapsedTimer {
37  public:
ElapsedTimer()38   ElapsedTimer() : start_(TicksNow()) {}
Elapsed()39   TickDelta Elapsed() { return TicksDelta(TicksNow(), start_); }
40 
41  private:
42   Ticks start_;
43 };
44 
45 #endif  // UTIL_TICKS_H_
46