C # how to test the code running time,

Source: Internet
Author: User

C # how to test the code running time,

Method 1:

System. diagnostics. stopwatch stopwatch = new Stopwatch (); stopwatch. start (); // Start to monitor the code running time // code to be tested .... stopwatch. stop (); // Stop monitoring TimeSpan timespan = stopwatch. elapsed; // obtain the total time measured by the current instance. double hours = timespan. totalHours; // total hour double minutes = timespan. totalMinutes; // The total minute double seconds = timespan. totalSeconds; // The total number of seconds. double milliseconds = timespan. totalMilliseconds; // The total number of milliseconds

Method 2:

System. diagnostics. stopwatch watch = new System. diagnostics. stopwatch (); watch. start (); // Start to monitor the code running time // watch the code to be tested. stop (); // Stop monitoring TimeSpan timespan = watch. elapsed; // obtain the total time measured by the current instance System. diagnostics. debug. writeLine ("opening window code execution time: {0} (millisecond)", timespan. totalMilliseconds); // The total number of milliseconds

 

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.