. net:c#: StopWatch

Source: Internet
Author: User

StopWatch class is used for calculate, the timespan for that procedure. In Debug Mode It'll be very useful.

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Diagnostics;6 7 namespacestopwatchtest8 {9     class ProgramTen     { One         Static voidMain (string[] args) A         { -Stopwatch SW =NewStopwatch (); -             strings =string. Empty; theStringBuilder SB =NewStringBuilder (); -             Const intTicks =100000; - SW. Start (); -              for(inti =0; I < ticks; i++) S + ="a"; + SW. Stop (); -TimeSpan ts =SW. Elapsed; +Console.WriteLine ("string Append ' a ' {0} times using time in time: {1}, in MilliSeconds: {2}, ticks: {3}", ticks. ToString (), TS. ToString (), ts.Milliseconds.ToString (), TS. Ticks.tostring ()); A SW. Restart (); at              for(inti =0; I < ticks; i++) sb. Append ("a"); - SW. Stop (); -             //ts = sw. Elapsed; -Console.WriteLine ("StringBuilder Append ' a ' {0} times using time in time: {1}, in MilliSeconds: {2}, ticks: {3}", ticks. ToString (), SW. Elapsed.tostring (), SW. Elapsedmilliseconds.tostring (), SW. Elapsedticks.tostring ()); -         } -     } in}

. net:c#: StopWatch

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.