Skip to content

Commit

Permalink
Merge pull request #87 from sveinungf/dev/addheaderrow
Browse files Browse the repository at this point in the history
AddHeaderRowAsync
  • Loading branch information
sveinungf authored Dec 15, 2024
2 parents 25473ef + f9dea59 commit c4c7277
Show file tree
Hide file tree
Showing 49 changed files with 491 additions and 260 deletions.
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
</PropertyGroup>
<ItemGroup>
<GlobalPackageReference Include="ErrorProne.NET.CoreAnalyzers" Version="0.4.0-beta.1" />
<GlobalPackageReference Include="Meziantou.Analyzer" Version="2.0.179" />
<GlobalPackageReference Include="Meziantou.Analyzer" Version="2.0.182" />
<GlobalPackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19" />
<GlobalPackageReference Include="PrimaryConstructorAnalyzer" Version="1.0.6" />
<GlobalPackageReference Include="Roslynator.Analyzers" Version="4.12.9" />
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="10.3.0.106239" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="Bogus" Version="35.6.1" />
<PackageVersion Include="ClosedXML" Version="0.104.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.1.1" />
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.2.0" />
<PackageVersion Include="EPPlusFree" Version="4.5.3.8" />
<PackageVersion Include="ErrorProne.NET.Structs" Version="0.4.0-beta.1" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Polyfill" Version="6.2.0" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="PublicApiGenerator" Version="11.1.0" />
<PackageVersion Include="PublicApiGenerator" Version="11.2.0" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.0" />
<PackageVersion Include="System.Drawing.Common" Version="4.7.3" />
<PackageVersion Include="System.Formats.Asn1" Version="9.0.0" />
Expand All @@ -38,7 +38,7 @@
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="TngTech.ArchUnitNET.xUnit" Version="0.11.1" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.5.0" />
<PackageVersion Include="Verify.Xunit" Version="28.3.1" />
<PackageVersion Include="Verify.Xunit" Version="28.5.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.assert" Version="2.9.2" />
<PackageVersion Include="Xunit.Combinatorial" Version="1.6.24" />
Expand Down
41 changes: 41 additions & 0 deletions SpreadCheetah.Benchmark/Benchmarks/AddHeaderRow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using SpreadCheetah.Styling;

namespace SpreadCheetah.Benchmark.Benchmarks;

[SimpleJob(RuntimeMoniker.Net48)]
[SimpleJob(RuntimeMoniker.Net90)]
[MemoryDiagnoser]
public class AddHeaderRow
{
private static readonly string[] HeaderNames =
[
"Id",
"First name",
"Last name",
"Date of birth",
"E-mail",
"Role"
];

[Params(100000)]
public int NumberOfRows { get; set; }

[Benchmark]
public async Task SpreadCheetahAddHeaderRow()
{
var options = new SpreadCheetahOptions { DefaultDateTimeFormat = null };
await using var spreadsheet = await Spreadsheet.CreateNewAsync(Stream.Null, options);
await spreadsheet.StartWorksheetAsync("Book1");
var style = new Style { Font = { Bold = true } };
var styleId = spreadsheet.AddStyle(style);

for (var i = 0; i < NumberOfRows; ++i)
{
await spreadsheet.AddHeaderRowAsync(HeaderNames, styleId);
}

await spreadsheet.FinishAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ namespace MyNamespace

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(1);
var headerNames = ArrayPool<string?>.Shared.Rent(1);
try
{
cells[0] = new StyledCell("Name", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false);
headerNames[0] = "Name";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 1), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo0(Spre

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(4);
var headerNames = ArrayPool<string?>.Shared.Rent(4);
try
{
cells[0] = new StyledCell("First", styleId);
cells[1] = new StyledCell("Second", styleId);
cells[2] = new StyledCell("Year", styleId);
cells[3] = new StyledCell("Score", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 4), token).ConfigureAwait(false);
headerNames[0] = "First";
headerNames[1] = "Second";
headerNames[2] = "Year";
headerNames[3] = "Score";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 4), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo0(Spre

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(4);
var headerNames = ArrayPool<string?>.Shared.Rent(4);
try
{
cells[0] = new StyledCell("FirstName", styleId);
cells[1] = new StyledCell("LastName", styleId);
cells[2] = new StyledCell("YearOfBirth", styleId);
cells[3] = new StyledCell("Initials", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 4), token).ConfigureAwait(false);
headerNames[0] = "FirstName";
headerNames[1] = "LastName";
headerNames[2] = "YearOfBirth";
headerNames[3] = "Initials";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 4), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo0(Spre

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(4);
var headerNames = ArrayPool<string?>.Shared.Rent(4);
try
{
cells[0] = new StyledCell("FirstName", styleId);
cells[1] = new StyledCell("LastName", styleId);
cells[2] = new StyledCell("YearOfBirth", styleId);
cells[3] = new StyledCell("Initials", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 4), token).ConfigureAwait(false);
headerNames[0] = "FirstName";
headerNames[1] = "LastName";
headerNames[2] = "YearOfBirth";
headerNames[3] = "Initials";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 4), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down Expand Up @@ -141,16 +141,16 @@ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo1(Spre

private static async ValueTask AddHeaderRow1Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(2);
var headerNames = ArrayPool<string?>.Shared.Rent(2);
try
{
cells[0] = new StyledCell("Id", styleId);
cells[1] = new StyledCell("Price", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false);
headerNames[0] = "Id";
headerNames[1] = "Price";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 2), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo0(Spre

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(1);
var headerNames = ArrayPool<string?>.Shared.Rent(1);
try
{
cells[0] = new StyledCell("Property", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false);
headerNames[0] = "Property";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 1), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ private static WorksheetRowDependencyInfo CreateWorksheetRowDependencyInfo0(Spre

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(2);
var headerNames = ArrayPool<string?>.Shared.Rent(2);
try
{
cells[0] = new StyledCell("Property1", styleId);
cells[1] = new StyledCell("Property2", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 2), token).ConfigureAwait(false);
headerNames[0] = "Property1";
headerNames[1] = "Property2";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 2), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ public MyGenRowContext()

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(3);
var headerNames = ArrayPool<string?>.Shared.Rent(3);
try
{
cells[0] = new StyledCell("Property", styleId);
cells[1] = new StyledCell("Property1", styleId);
cells[2] = new StyledCell("Property2", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false);
headerNames[0] = "Property";
headerNames[1] = "Property1";
headerNames[2] = "Property2";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 3), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public MyGenRowContext()

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(3);
var headerNames = ArrayPool<string?>.Shared.Rent(3);
try
{
cells[0] = new StyledCell("Property1", styleId);
cells[1] = new StyledCell("Property2", styleId);
cells[2] = new StyledCell("Property3", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 3), token).ConfigureAwait(false);
headerNames[0] = "Property1";
headerNames[1] = "Property2";
headerNames[2] = "Property3";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 3), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public MyGenRowContext()

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(1);
var headerNames = ArrayPool<string?>.Shared.Rent(1);
try
{
cells[0] = new StyledCell("Name", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false);
headerNames[0] = "Name";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 1), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down Expand Up @@ -114,15 +114,15 @@ private static ValueTask AddCellsAsRowAsync(SpreadCheetah.Spreadsheet spreadshee

private static async ValueTask AddHeaderRow1Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(1);
var headerNames = ArrayPool<string?>.Shared.Rent(1);
try
{
cells[0] = new StyledCell("Model", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false);
headerNames[0] = "Model";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 1), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public MyGenRowContext()

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(1);
var headerNames = ArrayPool<string?>.Shared.Rent(1);
try
{
cells[0] = new StyledCell("Name", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 1), token).ConfigureAwait(false);
headerNames[0] = "Name";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 1), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ public MyGenRowContext()

private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spreadsheet, SpreadCheetah.Styling.StyleId? styleId, CancellationToken token)
{
var cells = ArrayPool<StyledCell>.Shared.Rent(4);
var headerNames = ArrayPool<string?>.Shared.Rent(4);
try
{
cells[0] = new StyledCell("FirstName", styleId);
cells[1] = new StyledCell("LastName", styleId);
cells[2] = new StyledCell("YearOfBirth", styleId);
cells[3] = new StyledCell("Initials", styleId);
await spreadsheet.AddRowAsync(cells.AsMemory(0, 4), token).ConfigureAwait(false);
headerNames[0] = "FirstName";
headerNames[1] = "LastName";
headerNames[2] = "YearOfBirth";
headerNames[3] = "Initials";
await spreadsheet.AddHeaderRowAsync(headerNames.AsMemory(0, 4), styleId, token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells, true);
ArrayPool<string?>.Shared.Return(headerNames, true);
}
}

Expand Down
Loading

0 comments on commit c4c7277

Please sign in to comment.