Created
October 5, 2024 21:50
-
-
Save jahav/6b6c2e0dd0ae49d2e2980e0280a58a5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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