diff --git a/benchmarks/NPOI.Benchmarks/LargeExcelFileBenchmark.cs b/benchmarks/NPOI.Benchmarks/LargeExcelFileBenchmark.cs index 2e72b417e..4a63ac15f 100644 --- a/benchmarks/NPOI.Benchmarks/LargeExcelFileBenchmark.cs +++ b/benchmarks/NPOI.Benchmarks/LargeExcelFileBenchmark.cs @@ -1,5 +1,7 @@ using System.Net; using BenchmarkDotNet.Attributes; +using NPOI.OpenXml4Net.OPC; +using NPOI.XSSF.EventUserModel; using NPOI.XSSF.UserModel; namespace NPOI.Benchmarks; @@ -15,16 +17,17 @@ public class LargeExcelFileBenchmark [GlobalSetup] public void GlobalSetup() { + _filePath = Path.Combine("data","test-performance.xlsx"); + // a 17MB Excel file is large so download it only when needed - _filePath = Path.Combine(Path.GetTempPath(), "test-performance.xlsx"); - if (!File.Exists(_filePath)) + /*if (!File.Exists(_filePath)) { Console.WriteLine("Downloading file..."); new WebClient().DownloadFile( "https://github.com/GrapeCity/GcExcel-Java/raw/master/benchmark/files/test-performance.xlsx", _filePath); Console.WriteLine("File downloaded"); - } + }*/ var copyPath = Path.Combine(Path.GetTempPath(), "test-performance-copy.xlsx"); if (!File.Exists(copyPath)) @@ -37,12 +40,28 @@ public void GlobalSetup() } [Benchmark] - public void Load() + public void XSSFWorkbookLoad() { - var workbook = new XSSFWorkbook(_filePath); + var workbook = new XSSFWorkbook(_filePath, true); workbook.Dispose(); } + [Benchmark] + public void XSSFReaderLoad() + { + using var pkg = OPCPackage.Open(_filePath, PackageAccess.READ); + var reader = new XSSFReader(pkg); + + // Read shared strings table + var sst = reader.SharedStringsTable; + + // Read styles table + var styles = reader.StylesTable; + + // get streams of sheets data + var sheets = reader.GetSheetsData(); + } + [Benchmark] public void Write() { diff --git a/benchmarks/NPOI.Benchmarks/NPOI.Benchmarks.csproj b/benchmarks/NPOI.Benchmarks/NPOI.Benchmarks.csproj index 8700c69f6..ad3b78fec 100644 --- a/benchmarks/NPOI.Benchmarks/NPOI.Benchmarks.csproj +++ b/benchmarks/NPOI.Benchmarks/NPOI.Benchmarks.csproj @@ -1,4 +1,4 @@ - + Exe @@ -15,4 +15,10 @@ + + + Always + + + diff --git a/benchmarks/NPOI.Benchmarks/data/test-performance.xlsx b/benchmarks/NPOI.Benchmarks/data/test-performance.xlsx new file mode 100644 index 000000000..3e6782564 Binary files /dev/null and b/benchmarks/NPOI.Benchmarks/data/test-performance.xlsx differ diff --git a/openxml4Net/OPC/OPCPackage.cs b/openxml4Net/OPC/OPCPackage.cs index d53b3ea0d..44250164c 100644 --- a/openxml4Net/OPC/OPCPackage.cs +++ b/openxml4Net/OPC/OPCPackage.cs @@ -18,7 +18,7 @@ namespace NPOI.OpenXml4Net.OPC * @author Julien Chable, CDubet * @version 0.1 */ - public abstract class OPCPackage : RelationshipSource, ICloseable + public abstract class OPCPackage : RelationshipSource, ICloseable,IDisposable { /** @@ -1828,6 +1828,11 @@ public void UnregisterPartAndContentType(PackagePartName partName) this.contentTypeManager.RemoveContentType(partName); this.isDirty = true; } + + public void Dispose() + { + this.Close(); + } } }