I did a simple performance test between EPPlus and Spreadsheet Gear to find out if there is any significant difference that justifies the purchase of Spreadsheet Gear.
I am not an expert in any of the applications, so tests cannot be written in the most efficient way.
The test performs the following steps: 1. Opens an existing Excel file with 1000 rows and three columns. Saves three values ββto an object that is saved in the <> list. 2. Open a new Excel object 3. Create a title bar (bold) with a title for each column. 4. Record 1000 objects. 5. Save the new Excel file.
If I run this test as soon as EPPlus comes out the winner (approximately EPPlus = 280 ms, SG = 500 ms). If instead, I run the test 10 times in a row (opening a loop, copying, saving 10 times). A flexible table is faster (about once per file: EPPlus = 165 ms, SG = 95 ms). For 20 tests, the runtime is: EPPlus = 160 ms / file and SG = 60 ms / file.
It seems like (at least at least). Gears tables are getting faster and faster as more files I create. Can someone explain why EPPlus is slower when doing sequential tests? Can I make changes to the code to change this?
EPPlus Test Function:
var timer = new Stopwatch(); timer.Start(); var data = new List<Item>(); using (var excelIn = new ExcelPackage(new FileInfo(folder + fileIn))) { var sheet = excelIn.Workbook.Worksheets[1]; var row = 2; while (sheet.Cells[row, 1].Value != null) { data.Add(new Item() { Id = int.Parse(sheet.Cells[row, 1].Text), Title = sheet.Cells[row, 2].Text, Value = int.Parse(sheet.Cells[row, 3].Text) }); row++; } } using (var excelOut = new ExcelPackage()) { var sheet = excelOut.Workbook.Worksheets.Add("Out"); sheet.Cells.LoadFromCollection(data); sheet.InsertRow(1, 1); sheet.Cells[1, 1, 1, 3].Style.Font.Bold = true; sheet.Cells[1, 1].Value = "Id"; sheet.Cells[1, 2].Value = "Title"; sheet.Cells[1, 3].Value = "Value"; excelOut.SaveAs(new FileInfo(folder + "EPPlus_" + Guid.NewGuid() + ".xlsx")); } timer.Stop(); return timer.ElapsedMilliseconds;
Spreadsheet Engine:
var timer = new Stopwatch(); timer.Start(); var data = new List<Item>(); var excelIn = Factory.GetWorkbook(folder + fileIn); var sheetIn = excelIn.Worksheets[0]; var rowIn = 1; while (sheetIn.Cells[rowIn, 0].Value != null) { data.Add(new Item() { Id = int.Parse(sheetIn.Cells[rowIn, 0].Text), Title = sheetIn.Cells[rowIn, 1].Text, Value = int.Parse(sheetIn.Cells[rowIn, 2].Text) }); rowIn++; } excelIn.Close(); var excelOut = Factory.GetWorkbook(); var sheetOut = excelOut.Worksheets.Add(); sheetOut.Name = "Out"; var rowOut = 0; sheetOut.Cells[rowOut, 0, rowOut, 2].Font.Bold = true; sheetOut.Cells[rowOut, 0].Value = "Id"; sheetOut.Cells[rowOut, 1].Value = "Title"; sheetOut.Cells[rowOut++, 2].Value = "Value"; foreach (var item in data) { sheetOut.Cells[rowOut, 0].Value = item.Id; sheetOut.Cells[rowOut, 1].Value = item.Title; sheetOut.Cells[rowOut++, 2].Value = item.Value; } excelOut.SaveAs(folder + "SpreadsheetGear_" + Guid.NewGuid() + ".xlsx", FileFormat.OpenXMLWorkbook); excelOut.Close(); timer.Stop(); return timer.ElapsedMilliseconds;
Main function
var runs = 1; var testerG = new TestSpreadsheetGear(); var testerE = new TestEpPlus(); var msE = 0.0; var msG = 0.0; var i = 0; for (i = 0; i < runs; ++i) { msG += new TestSpreadsheetGear().Run(folder, originalFile); } for(i = 0; i < runs; ++i) { msE += new TestEpPlus().Run(folder, originalFile); } Console.WriteLine("Spreadsheet time: " + msG + ". Per file: " + msG / runs); Console.WriteLine("EP Plus time: " + msE + ". Per file: " + msE / runs); Console.ReadKey();