Skip to content

Instantly share code, notes, and snippets.

@jahav
Created October 5, 2024 21:50
Show Gist options
  • Save jahav/6b6c2e0dd0ae49d2e2980e0280a58a5f to your computer and use it in GitHub Desktop.
Save jahav/6b6c2e0dd0ae49d2e2980e0280a58a5f to your computer and use it in GitHub Desktop.
[MemoryDiagnoser(false)]
public class AverageBenchmark : IDisposable
{
private readonly XLWorkbook _wb;
private readonly IXLWorksheet _ws;
[Params(1000, 10000, 100000)]
public int RowsCount;
public AverageBenchmark()
{
_wb = new XLWorkbook();
_ws = _wb.AddWorksheet();
}
[GlobalSetup]
public void Setup()
{
_ws.Cell("A1").InsertData(Enumerable.Range(1, RowsCount));
_ws.Cell("B1").InsertData(Enumerable.Range(1, RowsCount).Reverse());
_ws.Cell("C1").InsertData(Enumerable.Range(1, RowsCount));
_ws.Cell("D1").InsertData(Enumerable.Range(1, RowsCount).Reverse());
}
[Benchmark]
public XLCellValue Average() => _ws.Evaluate($"AVERAGE(A1:B{RowsCount}, C1:D{RowsCount})");
[Benchmark]
public XLCellValue LegacyAverage() => _ws.Evaluate($"AVERAGE.LEGACY(A1:B{RowsCount}, C1:D{RowsCount})");
public void Dispose() => _wb.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment