Mega Code Archive

 
Categories / Delphi / Files
 

TXLSFile library benchmark compared to OLE Automation

Title: TXLSFile library benchmark compared to OLE Automation Question: Here we have compared TXLSFile library speed compared to OLE Automation with MS Excel Answer: TXLSFile is a Delphi library for working with MS Excel files without OLE. It is based on native Excel file format BIFF. We have created two Delphi applications, the first application uses TXLSFile, and the second application uses OLE Automation with MS Excel. Both applications make the same task of filling an Excel file with 10,000 different strings of length 5. Hardware -------- CPU: 800 MHz Memory: 128 Mb OS: MS Windows 2000 Professional Application 1 (uses TXLSFile library) ------------------------------------- Here is a part of Delphi source code for the first application: var xf: TXLSFile; I: Integer; begin { create new xls file } xf:= TXLSFile.Create; { fill worksheet with 10000 different strings } with xf.Workbook.Sheets[0] do for I:= 0 to 10000 -1 do Cells[I, 0].Value:= 'A' + IntToHex(I, 4); { save xls file } xf.SaveAs('testxlf.xls'); xf.Destroy; end; Application 1 execution time is 1 second. Application 2 (uses OLE Automation with MS Excel) ------------------------------------------------- Here is a part of Delphi source code for the first application: Note, that MS Excel application window is invisible here. olec: TOleContainer; ... var I: integer; begin { Open MS Excel as OLE server. MS Excel window is hidden } olec.CreateObject('Excel.Application', false); try { create new workbook } olec.OleObject.Workbooks.Add; { fill 10000 cells with different strings } for I:= 1 to 10000 do olec.OleObject.ActiveWorkbook.ActiveSheet.Range( 'A' + inttostr(I)):= 'A' + inttoHex(I, 4); { save xls file } olec.OleObject.ActiveWorkbook.SaveAs('testole.xls'); finally olec.DestroyObject; end; end; Application 2 execution time is about 95 seconds. Conclusion ---------- TXLSFile is about 100 times faster than OLE Automation with MS Excel.