In ASP. net2, precise page execution time was originally so simple!

Source: Internet
Author: User

In the past, when net1.1 was used, it was stupid to use datetime to calculate the page execution time. Sometimes, the result is quite confusing. Now, ready-made classes can be used, it can be accurate to microseconds (one second equals 1 million microseconds )!

The stopwatch class does not have many Members. It is located inIn the system. Diagnostics namespace, you usually only need to use the start and stop Methods elapsedmilliseconds and elapsed attributes. The example is as follows:

Stopwatch sp = new stopwatch (); // instantiate sp. Start () first; // start timing random r = new random (); // This is a piece of random number generatedCodeFor demonstration. It has no practical significance for (INT I = 0; I <10; I ++) {response. write (R. next (10); thread. sleep (1); // The thread control in C # is used here, so thatProgramWait for 1 ms thread here. sleep is often used for latency processing} sp. stop (); // end time response. write (sp. elapsedmilliseconds); // outputs timing results in milliseconds. You can also use the elapsed attribute to obtain detailed time.

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.