C # _ Stopwatch class,

Source: Internet
Author: User

C # _ Stopwatch class,

Namespace:System. Diagnostics

StopwatchAn instance can measure the running time at one interval or the total running time at multiple intervals. In the typicalStopwatchIn the solution, first call the Start method, then call the Stop method, and then use the Elapsed attribute to check the running time.

StopwatchThe instance is running or stopped. You can confirm it by using IsRunning.Stopwatch. UseStartYou can start measuring the running time.StopYou can stop the measurement run time. Pass attributesElapsed, ElapsedMilliseconds, or ElapsedTicks. You can query the running time attribute when the instance is running or stopped. Run Time attribute inStopwatchIt increases steadily during running; it remains unchanged when the instance is stopped.

By default,StopwatchThe running time value of the instance is equivalent to the total time interval of all measurements. Each callStartTotal running time count; each callStopEnd the current interval measurement, and freeze the cumulative running time value. You can use the Reset method to clear existingStopwatchThe cumulative running time in the instance.

StopwatchIn the Basic timer mechanism, the timer scale is counted to measure the running time. If the installed hardware and Operating System Support counters with high-resolution performanceStopwatchClass will use this counter to measure the running time; otherwise,StopwatchClass will use the system counter to measure the running time. Use the Frequency and IsHighResolution fields to determine the implementation.StopwatchTiming accuracy and resolution.

StopwatchClass helps you manage timing-related performance counters in your code. Specifically,FrequencyThe field and GetTimestamp methods can be used to replace unmanaged Win32 APIs.QueryPerformanceFrequencyAndQueryPerformanceCounter.

Note:

On a multi-processor computer, it does not matter on which processor the thread runs. However, due to a bug in the BIOS or hardware abstraction layer (HAL), different timing results may be obtained on different processors. To specify a processor association for a thread, use the ProcessThread. ProcessorAffinity method.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.