You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingBenchmarkDotNet.Order;usingClosedXML.Excel;usingDocumentFormat.OpenXml;usingDocumentFormat.OpenXml.Packaging;usingDocumentFormat.OpenXml.Spreadsheet;usingMiniExcelLibs;usingNPOI.HSSF.UserModel;usingOfficeOpenXml;usingSpreadCheetah;usingCell=SpreadCheetah.Cell;usingOpenXmlCell=DocumentFormat.OpenXml.Spreadsheet.Cell;usingOpenXmlCellValue=DocumentFormat.OpenXml.Spreadsheet.CellValues;namespaceConsoleApp1;[SimpleJob(RuntimeMoniker.Net90)][Orderer(SummaryOrderPolicy.FastestToSlowest)][MeanColumn,MemoryDiagnoser]publicclassXlsxBench{privateconststringSheetName="Test_Book";privateconstintNumberOfColumns=10;privatestaticreadonlyStreamOutputStream=newMemoryStream(6_000_000);[Params(20_000)]publicintNumberOfRows{get;set;}privateList<string>_columnNames=null!;privateList<Dictionary<string,object>>_miniExcelSheet=null!;privateList<List<string>>_values=null!;[Benchmark]publiclongClosedXml(){OutputStream.Seek(0,SeekOrigin.Begin);usingvarworkbook=newXLWorkbook();varworksheet=workbook.Worksheets.Add(SheetName);for(varrow=0;row<_values.Count;row++){varrowValues=_values[row];for(varcol=0;col<rowValues.Count;col++){worksheet.Cell(row+1,col+1).SetValue(rowValues[col]);}}workbook.SaveAs(OutputStream);returnOutputStream.Position;}[Benchmark]publiclongClosedXml_Batch(){OutputStream.Seek(0,SeekOrigin.Begin);usingvarworkbook=newXLWorkbook();varworksheet=workbook.Worksheets.Add(SheetName);worksheet.Cell(1,1).InsertData(_values);workbook.SaveAs(OutputStream);returnOutputStream.Position;}[Benchmark]publiclongEpPlus4(){OutputStream.Seek(0,SeekOrigin.Begin);usingvarpackage=newExcelPackage();varworksheet=package.Workbook.Worksheets.Add(SheetName);for(varrow=0;row<_values.Count;row++){varcolumns=_values[row];for(varcol=0;col<columns.Count;++col){worksheet.Cells[row+1,col+1].Value=columns[col];}}package.SaveAs(OutputStream);returnOutputStream.Position;}[Benchmark]publiclongMinExcel(){OutputStream.Seek(0,SeekOrigin.Begin);varvalues=newList<Dictionary<string,object>>(NumberOfRows);foreach(varrowValuesin_values){varrow=newDictionary<string,object>(NumberOfColumns);for(vari=0;i<rowValues.Count;i++){varcolumnName=_columnNames[i];varrowValue=rowValues[i];row.Add(columnName,rowValue);}values.Add(row);}OutputStream.SaveAs(values);returnOutputStream.Position;}[Benchmark]publiclongMinExcel_Cached(){OutputStream.Seek(0,SeekOrigin.Begin);for(varrowNumber=0;rowNumber<_values.Count;rowNumber++){varrowValues=_values[rowNumber];varrowData=_miniExcelSheet[rowNumber];for(vari=0;i<rowValues.Count;i++){varcolumnName=_columnNames[i];varrowValue=rowValues[i];rowData.Add(columnName,rowValue);}}OutputStream.SaveAs(_miniExcelSheet);foreach(varrowin_miniExcelSheet){row.Clear();}returnOutputStream.Position;}[Benchmark]publiclongNpoi(){OutputStream.Seek(0,SeekOrigin.Begin);varworkbook=newHSSFWorkbook();varsheet=workbook.CreateSheet(SheetName);// This Where the Data row starts fromvarrowIndex=0;//Iteration through some collectionforeach(varrowValuesin_values){varcurrentRow=sheet.CreateRow(rowIndex);for(varcolIndex=0;colIndex<rowValues.Count;colIndex++){varcell=currentRow.CreateCell(colIndex);cell.SetCellValue(rowValues[colIndex]);}rowIndex++;}workbook.Write(OutputStream);returnOutputStream.Position;}[Benchmark]publiclongOpenXml_Sax(){OutputStream.Seek(0,SeekOrigin.Begin);// Is a stream-based processor.// You only have a tiny part in memory at any time and you "sniff" the XML stream by implementing callback code for events like tagStarted() etc.// It uses almost no memory, but you can't do "DOM" stuff, like use xpath or traverse trees.// https://en.wikipedia.org/wiki/Simple_API_for_XMLusingvarxl=SpreadsheetDocument.Create(OutputStream,SpreadsheetDocumentType.Workbook);varworkbookPart=xl.AddWorkbookPart();varwsp=workbookPart.AddNewPart<WorksheetPart>();varoxw=OpenXmlWriter.Create(wsp);oxw.WriteStartElement(newWorksheet());oxw.WriteStartElement(newSheetData());varrowObject=newRow();varcellAttributes=new[]{newOpenXmlAttribute("t","","inlineStr")};varcell=newOpenXmlCell();varinlineString=newInlineString();for(varrow=0;row<NumberOfRows;row++){varrowAttributes=new[]{newOpenXmlAttribute("r","",(row+1).ToString())};oxw.WriteStartElement(rowObject,rowAttributes);varcolumns=_values[row];foreach(varcolincolumns){oxw.WriteStartElement(cell,cellAttributes);oxw.WriteStartElement(inlineString);oxw.WriteElement(newText(col));oxw.WriteEndElement();oxw.WriteEndElement();}oxw.WriteEndElement();}oxw.WriteEndElement();oxw.WriteEndElement();oxw.Close();oxw=OpenXmlWriter.Create(workbookPart);oxw.WriteStartElement(newWorkbook());oxw.WriteStartElement(newSheets());oxw.WriteElement(newSheet{Name="Sheet1",SheetId=1,Id=workbookPart.GetIdOfPart(wsp)});oxw.WriteEndElement();oxw.WriteEndElement();oxw.Close();returnOutputStream.Position;}[Benchmark]publiclongOpenXml_Dom(){OutputStream.Seek(0,SeekOrigin.Begin);// You load the whole thing into memory - it's a massive memory hog.// You can blow memory with even medium sized documents.// But you can use xpath and traverse the tree etc.// https://en.wikipedia.org/wiki/Document_Object_Modelusingvarxl=SpreadsheetDocument.Create(OutputStream,SpreadsheetDocumentType.Workbook);varworkbookpart=xl.AddWorkbookPart();workbookpart.Workbook=newWorkbook();varworksheetPart=workbookpart.AddNewPart<WorksheetPart>();varsheetData=newSheetData();worksheetPart.Worksheet=newWorksheet();worksheetPart.Worksheet.AppendChild(sheetData);varsheets=workbookpart.Workbook.AppendChild(newSheets());varsheet=newSheet{Id=workbookpart.GetIdOfPart(worksheetPart),SheetId=1,Name=SheetName};varcells=newOpenXmlElement[NumberOfColumns];for(varrow=0;row<_values.Count;++row){varrowValues=_values[row];for(varcol=0;col<rowValues.Count;++col){varinlineString=newInlineString();inlineString.AppendChild(newText(rowValues[col]));varcell=newOpenXmlCell{DataType=OpenXmlCellValue.InlineString};cell.AppendChild(inlineString);cells[col]=cell;}varrowObject=newRow(cells){RowIndex=(uint)row+1};sheetData.AppendChild(rowObject);}sheets.AppendChild(sheet);workbookpart.Workbook.Save();returnOutputStream.Position;}[Benchmark(Baseline=true)]publicasyncTaskSpreadCheetah(){OutputStream.Seek(0,SeekOrigin.Begin);awaitusingvarspreadsheet=awaitSpreadsheet.CreateNewAsync(OutputStream);awaitspreadsheet.StartWorksheetAsync(SheetName);foreach(varrowValuesin_values){varrowValuesCount=rowValues.Count;varrowCells=newList<Cell>(rowValuesCount);for(varcol=0;col<rowValuesCount;col++){rowCells.Add(newCell(rowValues[col]));}awaitspreadsheet.AddRowAsync(rowCells);}awaitspreadsheet.FinishAsync();}[Benchmark]publicasyncTaskSpreadCheetahDataCell(){OutputStream.Seek(0,SeekOrigin.Begin);awaitusingvarspreadsheet=awaitSpreadsheet.CreateNewAsync(OutputStream);awaitspreadsheet.StartWorksheetAsync(SheetName);foreach(varrowValuesin_values){varrowValuesCount=rowValues.Count;varrowCells=newDataCell[rowValuesCount];for(varcol=0;col<rowValuesCount;col++){rowCells[col]=newDataCell(rowValues[col]);}awaitspreadsheet.AddRowAsync(rowCells);}awaitspreadsheet.FinishAsync();}[GlobalSetup]publicvoidSetup(){_columnNames=Enumerable.Range(0,NumberOfColumns).Select(c =>$"Column{c}").ToList();_values=newList<List<string>>(NumberOfRows);for(varrow=1;row<=NumberOfRows;row++){varcells=newList<string>(NumberOfColumns);_values.Add(cells);for(varcol=1;col<=NumberOfColumns;col++){cells.Add($"{col}-{row}");}}_miniExcelSheet=newList<Dictionary<string,object>>(NumberOfRows);foreach(var_in_values){_miniExcelSheet.Add(newDictionary<string,object>(NumberOfColumns));}}}
I wrot a post in telegram about your perferct library!
The text was updated successfully, but these errors were encountered:
Hi! Please, update your benchmarks with other popular libraries
I wrot a post in telegram about your perferct library!
The text was updated successfully, but these errors were encountered: