private static void Main() { // Save the time stamp and starting memory Console.WriteLine(@"Starting ..."); var start = DateTime.Now; var startMemory = _maxMemory = Process.GetCurrentProcess().WorkingSet64; // Profile the excel generation var factory = new ExcelFactory(); using (var ms = new MemoryStream()) { using (var excel = factory.CreateWriter(ms)) { excel.WriteRecords(GenerateRecords()); // Call close before we dispose of our classes, so we can measure the total memory used excel.Close(); _maxMemory = Math.Max(Process.GetCurrentProcess().WorkingSet64, _maxMemory); } } // Write out how long it took and how much memory was used var usedMemory = _maxMemory - startMemory; var elapsed = DateTime.Now - start; Console.WriteLine(@"Done!"); Console.WriteLine(@"Process took: {0} minutes and {1} seconds", Math.Floor(elapsed.TotalMinutes), elapsed.Seconds); Console.WriteLine(@"Process used: {0:F1}MB", usedMemory / 1048576.0); }
private static void Main() { // Save the time stamp var start = DateTime.Now; Console.WriteLine(@"Starting ..."); // Profile the excel generation var factory = new ExcelFactory(); using (var ms = new MemoryStream()) { using (var excel = factory.CreateWriter(ms)) { excel.WriteRecords(GenerateRecords()); } } // Write out how long it took var elapsed = DateTime.Now - start; Console.WriteLine(@"Done!"); Console.WriteLine(@"Process took: {0} minutes and {1} seconds", Math.Floor(elapsed.TotalMinutes), elapsed.Seconds); }