数组、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<int> intList = new List<int>();
    sw = new Stopwatch();
    sw.Start();
    for (int i = 0; i < 100; i++)
    {
        intList.Add(i);
    }
    sw.Stop();
    Console.WriteLine(" Add 0 ~ 100 to List<int> : " + sw.Elapsed);

    Console.ReadLine();
}

效果如图:

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

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

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

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

新闻标题:数组、LIst<>、ArrayList的性能对比
URL链接:https://www.cdcxhl.com/article42/picdhc.html

成都网站建设公司_创新互联,为您提供做网站网站收录企业建站关键词优化软件开发自适应网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

营销型网站建设