Created
September 28, 2023 13:12
-
-
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.
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
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