C#编译版本性能比较

代码

        public class Class1
        {
            public string str1 { get; set; }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            GC.Collect();
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            HashSet vs = new HashSet();
            for (int i = 0; i < 9999999; i++)
            {
                vs.Add(new Class1() { str1 = Guid.NewGuid().ToString() });
            }
            Console.WriteLine(vs.Count);
            sw.Stop();
            TimeSpan ts2 = sw.Elapsed;
            Console.WriteLine("example2 time {0}", ts2.TotalMilliseconds);
        }

VS中运行

Debug

X86

9999999
example2 time 13534.0177
9999999
example2 time 13355.5263
9999999
example2 time 13628.2633
9999999
example2 time 14127.6151
9999999
example2 time 13673.3993

X64

9999999
example2 time 9574.1108
9999999
example2 time 9941.6061
9999999
example2 time 9448.7378
9999999
example2 time 9828.5361
9999999
example2 time 9701.5338

any CPU

9999999
example2 time 13758.4628
9999999
example2 time 13096.1767
9999999
example2 time 13995.4884
9999999
example2 time 13626.3217
9999999
example2 time 13427.1795

Release

X64

9999999
example2 time 9792.5497
9999999
example2 time 9246.7111
9999999
example2 time 9439.7221
9999999
example2 time 9694.3204
9999999
example2 time 9821.8541

未在VS中运行

Release X64

9999999
example2 time 8923.5303
9999999
example2 time 9135.0211
9999999
example2 time 9180.5027
9999999
example2 time 8820.792
9999999
example2 time 9479.1569

Debug X64

9999999
example2 time 8845.395
9999999
example2 time 9023.3323
9999999
example2 time 9219.4217
9999999
example2 time 9294.6651
9999999
example2 time 9626.5562

你可能感兴趣的:(C#编译版本性能比较)