为什么铬实施 Time::Now ?有什么好处?

why did the chromium implement Time::Now ? what is the benefit?

代码段如下,代码来自chromium,为什么?

// Initilalize initial_ticks and initial_time
void InitializeClock() {
  initial_ticks = TimeTicks::Now();
  // Initilalize initial_time 
  initial_time = CurrentWallclockMicroseconds();
}// static
Time Time::Now() {
  if (initial_time == 0)
    InitializeClock();

  // We implement time using the high-resolution timers so that we can get
  // timeouts which are smaller than 10-15ms.  If we just used
  // CurrentWallclockMicroseconds(), we'd have the less-granular timer.
  //
  // To make this work, we initialize the clock (initial_time) and the
  // counter (initial_ctr).  To compute the initial time, we can check
  // the number of ticks that have elapsed, and compute the delta.
  //
  // To avoid any drift, we periodically resync the counters to the system
  // clock.
  while (true) {
    TimeTicks ticks = TimeTicks::Now();

    // Calculate the time elapsed since we started our timer
    TimeDelta elapsed = ticks - initial_ticks;

    // Check if enough time has elapsed that we need to resync the clock.
    if (elapsed.InMilliseconds() > kMaxMillisecondsToAvoidDrift) {
      InitializeClock();
      continue;
    }

    return Time(elapsed + Time(initial_time));
  }
}

我假设您的答案就在您粘贴的代码的注释中:

// We implement time using the high-resolution timers so that we can get
// timeouts which are smaller than 10-15ms.  If we just used
// CurrentWallclockMicroseconds(), we'd have the less-granular timer.

因此 Now 给出了高分辨率的时间值,当您需要比 10-15 毫秒更高的分辨率时,这很有用,正如他们在评论中所述。例如,如果你想每 100 ns 重新安排一个任务,你需要更高的分辨率,或者如果你想测量某事的执行时间 - 10-15 ms 是永恒的。