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
336 views
in Technique[技术] by (71.8m points)

.net 4.0 - How to get ticks from QueryPerformanceCounter in C#?

I need to replace Stopwatch to avoid using getters for its properties. I am going to implement it using QueryPerformanceCounter. I only need ticks nothing else.

Can anyone provide a code snipet please, to get correct ticks (1/10000 of ms) or any other small but stable value.

Please note my server sets clock granularity down to 0.5 ms (not sure if it affects QueryPerformanceCounter) but just for you to know.

Please also note - I do not need a timer. I only need to measure time intervals between parts of code.

EDIT: to avoid confusion I really want to know what is lpPerformanceCount in QueryPerformanceCounter(out long lpPerformanceCount);

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.gettimestamp.aspx

Stopwatch.GetTimestamp

You don't have to instantiate a Stopwatch object, GetTimestamp should return the number of ticks regardless of its context.


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

...