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.