Execution time of statistical code for performance analysis

Source: Internet
Author: User

First, the Stopwatch class under the System.Diagnostics namespace
//Instantiate a timerStopwatch Watch =NewStopwatch ();//Start TimingWatch. Start ();//here is the run code to be evaluated for(inti =1; I <1000000; i++) {}//Execute the task to be timed//End TimingWatch. Stop ();//gets the total elapsed time (in milliseconds) measured by the current instancestringTime =Watch. Elapsedmilliseconds.tostring ();//Description: Stopwatch provides several methods to control the Stopwatch object. The Start method starts a timing operation, and the Stop method stops timing. To avoid this, zero the object with the Reset method before the second timeConsole.WriteLine ("Elapsed: {0}", watch. Elapsed); Console.WriteLine ("In milliseconds: {0}", watch. Elapsedmilliseconds); Console.WriteLine ("In Timer ticks: {0}", watch. Elapsedticks);
Second, the DateTime class
DateTime StartTime =DateTime.Now; Console.WriteLine ("Started: {0}", StartTime); //Execute the task to be timed for(intI=1; I <100000; i++) {} DateTime stoptime=DateTime.Now; Console.WriteLine ("Stopped: {0}", StopTime); TimeSpan ElapsedTime= StopTime-StartTime; Console.WriteLine ("Elapsed: {0}", ElapsedTime); Console.WriteLine ("In hours:"+elapsedtime.totalhours); Console.WriteLine ("In minutes:"+elapsedtime.totalminutes); Console.WriteLine ("In seconds:"+elapsedtime.totalseconds); Console.WriteLine ("In milliseconds:"+ elapsedtime.totalmilliseconds);

Execution time of statistical code for performance analysis

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.