Use of C#stopwatch, performance testing

Source: Internet
Author: User

First, start or continue to measure the elapsed time of an interval, then stop, last reset time, output.

usingSystem;usingSystem.Collections.Generic;usingSystem.Diagnostics;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classtestperformance:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {        /*Var Performance Test*/Stopwatch STW=NewStopwatch (); List<Long> intlist =Newlist<Long>(); StW.        Start ();  for(Longi =0; I <10000000; i++)        {            varindex = i;//use Var to transfer and transfer outintlist.        ADD (index); } STW.        Stop (); Label1.Text=STW.         Elapsed.Ticks.ToString (); StW.        Reset (); /*Int Performance Test*/List<Long> intlist2 =Newlist<Long>(); StW. Start ();//Start Time         for(Longi =0; I <1000000; i++)        {            Longindex = i;//use int to transfer and transfer outIntlist2.        ADD (index); } STW.        Stop (); Label2.Text=STW.        Elapsed.Ticks.ToString (); StW.        Reset (); /*Object Performance Test*/STW. Start ();//Start TimeList<Long> intlist3 =Newlist<Long>();  for(Longi =0; I <1000000; i++)        {            Objectindex = i;//use object to transfer and transfer outIntlist3. ADD (Long) (index); } STW.        Stop (); Label3.text=STW.     Elapsed.Ticks.ToString (); }}

Second, front-end display

<%@ Page language="C #"autoeventwireup="true"codefile="TestPerformance.aspx.cs"inherits="testperformance"%><! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Server"><meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/> <title></title>"Form1"runat="Server"> <div>Var:<asp:label id="Label1"runat="Server"text="Var"></asp:Label><br/>Int:<asp:label id="Label2"runat="Server"text="Int"></asp:Label><br/>Object:<asp:label id="Label3"runat="Server"text="Object"></asp:Label> </div> </form></body>

Three, show the result

Use of C#stopwatch, performance testing

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.