What are timer ticks, the unit used by Stopwatch.ElapsedTicks

前端 未结 3 1200
逝去的感伤
逝去的感伤 2020-12-11 15:51

I used to think that

  • Stopwatch.ElapsedTicks was equal to
  • Stopwatch.Elapsed.Ticks.

But it isn\'t. While the

3条回答
  •  一整个雨季
    2020-12-11 16:19

    From the docs:

    The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation.

    Yes, it's a pain that "ticks" is overloaded to mean two different things :(

    I think it's basically because Stopwatch is giving a pretty "raw" view of a performance counter, which can have different implementations for what it means by a "tick".

提交回复
热议问题