Skip to content

Instantly share code, notes, and snippets.

@jahav
Created September 28, 2023 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahav/bdc5fe3c90f25544ca6ae1394bbe3561 to your computer and use it in GitHub Desktop.
Save jahav/bdc5fe3c90f25544ca6ae1394bbe3561 to your computer and use it in GitHub Desktop.
Create a file with 250 000 rows and 15 columns and print out how long it takes.
var sw = Stopwatch.StartNew();
using var wb = new XLWorkbook();
var sheet = wb.AddWorksheet();
// Lazy created data
var data = Enumerable.Range(0, 250_000).Select(_ =>
{
// Always create new string, like database provider would
var text = Enumerable.Range(0, 10).Select<int, object>(_ => new string("Hello world"));
var numbers = Enumerable.Range(0, 5).Cast<object>();
return text.Concat(numbers);
});
sheet.Cell("A1").InsertData(data);
sw.Stop();
Console.WriteLine($"Insert data: {sw.ElapsedMilliseconds}ms");
sw.Restart();
wb.SaveAs(@"large_250_000.xlsx");
sw.Stop();
Console.WriteLine($"Save data: {sw.ElapsedMilliseconds}ms");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment