zoukankan      html  css  js  c++  java
  • 装箱和拆箱的性能损耗以及没有装箱和拆箱的性能损耗

       List<int> listint = new List<int>();
                DateTime start = DateTime.Now;
                for (int i = 0; i < 10000000; i++)
                {
                    listint.Add(i);
                }
                DateTime stop = DateTime.Now;
        
                Console.WriteLine("没有装箱和拆箱耗时:"+(stop-start));
                List<string> list1 = new List<string>();
                DateTime start1 = DateTime.Now;
                for (int i = 0; i < 10000000; i++)
                {
                    list1.Add(i.ToString());
                }
                DateTime stop1 = DateTime.Now;
                Console.WriteLine("装箱箱耗时:" + (stop1 - start1));
    
                List<string> list2 = new List<string>();
                DateTime start2 = DateTime.Now;
                for (int i = 0; i < 10000000; i++)
                {
                    listint.Add(int.Parse(list1[i]));
                }
                DateTime stop2 = DateTime.Now;
                Console.WriteLine("拆箱箱耗时:" + (stop2 - start2));

    下面给你们分享几次测试的结果

  • 相关阅读:
    观察者模式
    模版方法
    event
    设计模式之观察者模式
    BOM
    javascript基础语法&4
    Document Object Model
    javascript基础语法&3
    javaScript基础语法&1
    sublimeText3安装
  • 原文地址:https://www.cnblogs.com/zxp6/p/9185118.html
Copyright © 2011-2022 走看看