Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

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

I used to think that

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

But it isn't. While the latter is a number of 100 nanoseconds periods, the former use a mysterious unit called timer ticks. I wonder what those are, and why are they different from the usual unit of measurement?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...