筆記:C#時間效能

C#知識

最近筆者在優化一些系統效能部分,先筆記一下常用的片段

            Console.WriteLine("hello world Create Test Data");
            List<Person> persons = new List<Person>();
            Stopwatch sw = new Stopwatch();
            sw.Reset();
            sw.Start();
            for (int i = 0; i < 1000000; i++)
            {
                persons.Add(new Person { Name = "Jane" + i,Sex = "M"});
            }
            sw.Stop();
            Console.WriteLine(@"Create Data Count:" + persons.Count);
            Console.WriteLine(@"Time Seconds:" + (sw.ElapsedMilliseconds / 1000d).ToString());
            sw.Reset();
            

專門用來評估一段程式的時間跑的效能...

老E隨手寫