V8 Project
v8::base::anonymous_namespace{time-unittest.cc} Namespace Reference

Functions

template<typename T >
static void ResolutionTest (T(*Now)(), TimeDelta target_granularity)
 

Function Documentation

◆ ResolutionTest()

template<typename T >
static void v8::base::anonymous_namespace{time-unittest.cc}::ResolutionTest ( T(*)()  Now,
TimeDelta  target_granularity 
)
static

Definition at line 116 of file time-unittest.cc.

116  {
117  // We're trying to measure that intervals increment in a VERY small amount
118  // of time -- according to the specified target granularity. Unfortunately,
119  // if we happen to have a context switch in the middle of our test, the
120  // context switch could easily exceed our limit. So, we iterate on this
121  // several times. As long as we're able to detect the fine-granularity
122  // timers at least once, then the test has succeeded.
123  static const TimeDelta kExpirationTimeout = TimeDelta::FromSeconds(1);
124  ElapsedTimer timer;
125  timer.Start();
126  TimeDelta delta;
127  do {
128  T start = Now();
129  T now = start;
130  // Loop until we can detect that the clock has changed. Non-HighRes timers
131  // will increment in chunks, i.e. 15ms. By spinning until we see a clock
132  // change, we detect the minimum time between measurements.
133  do {
134  now = Now();
135  delta = now - start;
136  } while (now <= start);
137  EXPECT_NE(static_cast<int64_t>(0), delta.InMicroseconds());
138  } while (delta > target_granularity && !timer.HasExpired(kExpirationTimeout));
139  EXPECT_LE(delta, target_granularity);
140 }
#define T(name, string, precedence)
Definition: token.cc:25

References T.