资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

数组、LIst<>、ArrayList的性能对比

static void Main(string[] args)
{
    Stopwatch sw = new Stopwatch();

    int[] intArray = new int[100];
    sw.Start();
    for (int i = 0; i < 100; i++)
    {
        intArray[i] = i;
    }
    sw.Stop();
    Console.WriteLine(" Add 0 ~ 100 to int[100] : " + sw.Elapsed);

    ArrayList list = new ArrayList();
    sw = new Stopwatch();
    sw.Start();
    for (int i = 0; i < 100; i++)
    {
        list.Add(i);
    }
    sw.Stop();
    Console.WriteLine(" Add 0 ~ 100 to ArrayList : " + sw.Elapsed);

    List intList = new List();
    sw = new Stopwatch();
    sw.Start();
    for (int i = 0; i < 100; i++)
    {
        intList.Add(i);
    }
    sw.Stop();
    Console.WriteLine(" Add 0 ~ 100 to List : " + sw.Elapsed);

    Console.ReadLine();
}

效果如图:

合山网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。成都创新互联公司于2013年开始到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司

数组、LIst<> 、 ArrayList的性能对比

可以看到数组明显比较快,但是必需初始化长度

目测原因是往ArrayList中添加元素时发生了装箱操作


本文标题:数组、LIst<>、ArrayList的性能对比
本文地址:http://cdkjz.cn/article/picdhc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220