Operation Performance of generic and general set class value types

Source: Internet
Author: User

Access killkill
Http://blog.csdn.net/killlkilll/archive/2006/12/23/1457022.aspx

List <t> the value type operation does not require packing; arraylist is required.

Class Program
...{
Static void main (string [] ARGs)
...{
Stopwatch Sw = new stopwatch ();
Sw. Start ();
Ilist <somevaluetye> List = new list <somevaluetye> ();
For (INT I = 0; I <1000; I ++)
...{
List. Add (New somevaluetye (I, "test "));
}
Sw. Stop ();
Console. writeline (SW. elapsed );
Sw. Reset ();
Arraylist Al = new arraylist ();
For (INT I = 0; I <1000; I ++)
...{
Al. Add (New somevaluetye (I, "test "));
}
Sw. Start ();
Sw. Stop ();
Console. writeline (SW. elapsed );
Console. Readline ();
}
}

Struct somevaluetye
...{
Public int m_testint;
Public String m_teststr;
Public somevaluetye (INT intvalue, string strvalue)
...{
M_testint = intvalue;
M_teststr = strvalue;
}
}

Execution result:
00:00:00. 0022005
00:00:00. 0000296

This is not an order of magnitude difference.

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.