Last active
July 2, 2020 20:45
-
-
Save govert/8fc38cf335462a1d9baef8a61f2bba6d to your computer and use it in GitHub Desktop.
Revisions
-
govert revised this gist
Jul 2, 2020 . 1 changed file with 19 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,33 +1,41 @@ using System; using System.Diagnostics; using ExcelDna.Integration; using static ExcelDna.Integration.XlCall; namespace SetValuePerf { public static class Macros { [ExcelCommand(ShortCut = "^D")] // Ctrl + Shift + D public static void DumpValues() { var numWritesInput = Excel(xlfInput, "Number of writes:", 1, "SetValuePerf Test", 20000); if (numWritesInput is bool) return; var numWrites = Convert.ToInt32(numWritesInput); var sw = Stopwatch.StartNew(); for (int i = 0; i < numWrites; i++) { var r = new ExcelReference(i, i, 0, 1); r.SetValue(new object[,] { { $"Info - {i}", DateTime.Now } }); } sw.Stop(); new ExcelReference(0, 4).SetValue("Writes / ElapsedMs / Writes per ms:"); new ExcelReference(0, 0, 5, 7).SetValue(new object[,] { { numWrites, sw.ElapsedMilliseconds, (double)numWrites / sw.ElapsedMilliseconds } }); } [ExcelCommand(ShortCut = "^E")] // Ctrl + Shift + E public static void DumpValuesEverywhere() { var numWritesInput = Excel(xlfInput, "Number of writes:", 1, "SetValuePerf Test", 20000); if (numWritesInput is bool) return; var numWrites = Convert.ToInt32(numWritesInput); // Add 9 new sheets, named Sheet2 - Sheet10 for (int s = 0; s < 9; s++) { @@ -36,14 +44,15 @@ public static void DumpValuesEverywhere() // Scatter some values around the various sheets var sw = Stopwatch.StartNew(); for (int i = 0; i < numWrites; i++) { var r = new ExcelReference(i/10, i/10, 0, 1, $"Sheet{i%10 + 1}"); r.SetValue(new object[,] { { $"Info - {i}", DateTime.Now } }); } sw.Stop(); Excel(xlcWorkbookActivate, "Sheet1"); new ExcelReference(0, 4).SetValue("Writes / ElapsedMs / Writes per ms:"); new ExcelReference(0, 0, 5, 7).SetValue(new object[,] { { numWrites, sw.ElapsedMilliseconds, (double)numWrites / sw.ElapsedMilliseconds } }); } } } -
govert created this gist
Jul 2, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using ExcelDna.Integration; using static ExcelDna.Integration.XlCall; namespace SetValuePerf { public static class Macros { [ExcelCommand(ShortCut = "^D")] // Ctrl + Shift + D public static void DumpValues() { var sw = Stopwatch.StartNew(); for (int i = 0; i < 20000; i++) { var r = new ExcelReference(i, i, 0, 1); r.SetValue(new object[,] { { $"Info - {i}", DateTime.Now } }); } new ExcelReference(0, 4).SetValue("ElapsedMs:"); new ExcelReference(0, 5).SetValue(sw.ElapsedMilliseconds); } [ExcelCommand(ShortCut = "^E")] // Ctrl + Shift + E public static void DumpValuesEverywhere() { // Add 9 new sheets, named Sheet2 - Sheet10 for (int s = 0; s < 9; s++) { Excel(xlcWorkbookInsert, 1); } // Scatter some values around the various sheets var sw = Stopwatch.StartNew(); for (int i = 0; i < 20000; i++) { var r = new ExcelReference(i/10, i/10, 0, 1, $"Sheet{i%10 + 1}"); r.SetValue(new object[,] { { $"Info - {i}", DateTime.Now } }); } new ExcelReference(0, 4).SetValue("ElapsedMs:"); new ExcelReference(0, 0, 5, 5, "Sheet1").SetValue(sw.ElapsedMilliseconds); Excel(xlcWorkbookActivate, "Sheet1"); } } }