List<string> strList = new List<string>();
泛型创建时,按理指定容量性能优于默认容量,但经过测试发现,指定容量并没有什么性能优势?请高手指点。测试结果:
            /*************************************************
             * 测试用例:集合初始化--指定容量和不指定容量性能对比
             * 结论:指定容量和不指定容量性能差别不大,按理:指定容量性能会好点
             * 测试结果如下:(时间为毫秒)
             * --------------------------------------
             * 数据:     | 10W    | 100W  |  1000W
             * --------------------------------------
             * 不指定容量 |  16    |   207  |   2867
             * ---------------------------------------
             * 指定容量   |  18    |   292   |   2863 
             *
             */
具体测试用例如下:            Stopwatch watcher = new Stopwatch();            #region 测试用例--集合初始化时指定容量和不指定容量性能对比            #region 不指定容量
            watcher.Reset();
            watcher.Start();
            int count = 1000000;
            List<string> strList = new List<string>();
            for (int i = 0; i < count; i++)
            {
                strList.Add(i.ToString());
            }
            Console.WriteLine("不指定集合容量:{0}", watcher.ElapsedMilliseconds);
            #endregion            #region 指定容量
            watcher.Reset();
            watcher.Start();
            List<string> strList2 = new List<string>(count);
            for (int i = 0; i < count; i++)
            {
                strList2.Add(i.ToString());
            }
            Console.WriteLine("指定集合容量:{0}", watcher.ElapsedMilliseconds);
            #endregion
            #endregion