. Net c # Stopwatch usage

Source: Internet
Author: User

Generally, we want to test the method or the type with higher efficiency. We can use the Stopwatch class for testing. I only know it now.

Let's look at a small example.

Prerequisite: first reference using System. Diagnostics; namespace.

1 // instantiate a sw
2 Stopwatch sw = new Stopwatch ();
3 // start counting
4 sw. Start ();
5
6 // instantiate an sb
7 StringBuilder sb = new StringBuilder ();
8
9 // Loop
10 for (int I = 0; I <10000; I ++)
11 {
12 // append
13 sb. Append (I );
14}
15 // output time in milliseconds
16 Console. WriteLine (sw. ElapsedMilliseconds );
17
18 // reset to 0
19 sw. Reset ();
20 // start counting
21 sw. Start ();
22 // define an s string
23 string s = "";
24
25 // Loop
26 for (int I = 0; I <10000; I ++)
27 {
28 s = s + I;
29
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.