Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions benchmarks/NPOI.Benchmarks/LargeExcelFileBenchmark.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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))
Expand All @@ -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()
{
Expand Down
8 changes: 7 additions & 1 deletion benchmarks/NPOI.Benchmarks/NPOI.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -15,4 +15,10 @@
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>

<ItemGroup>
<None Update="data\test-performance.xlsx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
7 changes: 6 additions & 1 deletion openxml4Net/OPC/OPCPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

/**
Expand Down Expand Up @@ -1828,6 +1828,11 @@ public void UnregisterPartAndContentType(PackagePartName partName)
this.contentTypeManager.RemoveContentType(partName);
this.isDirty = true;
}

public void Dispose()
{
this.Close();
}
}

}
Loading