Skip to content

Instantly share code, notes, and snippets.

@jahav
Created December 23, 2022 23:22
Show Gist options
  • Save jahav/b4e543a0fcfe449acb474b70482fb6a7 to your computer and use it in GitHub Desktop.
Save jahav/b4e543a0fcfe449acb474b70482fb6a7 to your computer and use it in GitHub Desktop.
1838-test.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using ClosedXML.Excel;
namespace ClosedXML.Sandbox
{
internal static class Program
{
private static DataTable GetTable()
{
DataTable table = new DataTable();
// add columns
for (var col = 1; col <= 245; col++)
{
table.Columns.Add("col_" + col.ToString(), typeof(string));
}
List<string> valuesList = new List<String>();
foreach (DataColumn dc in table.Columns)
{
valuesList.Add("testing 101.001000000000 test");
}
for (var row = 1; row <= 50000; row++)
{
table.Rows.Add(valuesList.ToArray<string>());
}
return table;
}
private static void Main(string[] args)
{
var table = GetTable();
var stopwatch = Stopwatch.StartNew();
XLWorkbook workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("fgtesting");
worksheet.Cell(1, 1).InsertData(table);
Console.WriteLine($"Create workbook: {stopwatch.Elapsed}");
// average 1.06min 245 columns 50k rows (no styles)
var memoryStream = new MemoryStream();
stopwatch.Restart();
workbook.SaveAs(memoryStream);
Console.WriteLine($"Save workbook: {stopwatch.Elapsed}");
stopwatch.Restart();
workbook.Dispose();
Console.WriteLine($"Dispose of workbook : {stopwatch.Elapsed}");
stopwatch.Restart();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Console.WriteLine($"GC cleanup: {stopwatch.Elapsed}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment