Frage

I'm not talking about the bloodsucking spider-like disease-spreader, but rather the sort of tick I recorded here:

Stopwatch noLyme = new Stopwatch();
noLyme.Start();
. . .
noLyme.Stop();
MessageBox.Show(string.Format(
   "elapsed milliseconds == {0}, elapsed ticks == {1}", 
   noLyme.ElapsedMilliseconds, noLyme.ElapsedTicks));

What the message box showed me was 17357 milliseconds and 56411802 ticks; this equates to 3250.089416373797 ticks per millisecond, or approximately 3.25 million ticks per second.

Since the ratio is such an odd one (3250.089416373797:1), I assume the time length of a tick changes based on hardware used, or other factors. That being the case, in what practical way are tick counts used? To me, it seems milliseconds hold more value. IOW: why would I care about ticks (the variable time slices)?

War es hilfreich?

Lösung 3

ticks are the raw, low level units in which the hardware measures time.

It's like asking "what use are bits when we can use ints". Well, if we didn't have bits, ints wouldn't exist!

However, ticks can be useful. When counting ticks, converting them to milliseconds is a costly process. When measuring accurately, you can count everything in ticks and convert the results to seconds at the end of the process. When comparing measurements, absolute values nay not be relevant, it may only be relative differences that are of interest.

Of course, in these days of high level language and multitasking there aren't many cases where you would go to the bare metal in this way, but why shouldn't the raw hardware value be exposed through the higher level interfaces?

Andere Tipps

From the documentation (with Frequency being another property of the Stopwatch):

Each tick in the ElapsedTicks value represents the time interval equal to 1 second divided by the Frequency.

Stopwatch.ElapsedTicks (MSDN)

Ticks are useful if you need very precise timing based on the specifics of your hardware.

You would use ticks if you want to know a very precise performance measurement that is specific to a given machine. Internal hardware mechanisms determine the conversion from ticks to actual time.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top