裝箱和拆箱的性能損耗以及沒有裝箱和拆箱的性能損耗
阿新 • • 發佈:2018-06-15
int color alt src 測試 tar con string mage
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));
下面給你們分享幾次測試的結果
裝箱和拆箱的性能損耗以及沒有裝箱和拆箱的性能損耗