程序中为了计算使用时间,通常Stopwatchshi'y
Stopwatch watch = Stopwatch.StartNew(); using (RetailEntities context = new RetailEntities()) { foreach (var entity in customers) { context.Customers.Add(entity); } context.SaveChanges(); } watch.Stop(); Console.WriteLine(string.Format( "{0} customers are created, cost {1} milliseconds.", customerCount, watch.ElapsedMilliseconds));