From 4b0d29da671343e06547dcaadab7a660afdf1d42 Mon Sep 17 00:00:00 2001 From: Lucas Viana Date: Sun, 15 Oct 2023 22:58:22 -0300 Subject: [PATCH] perf(memory-leaks): introduce Tasks.Arrays.Length --- Tests/YDotNet.Tests.Driver/Program.cs | 2 +- .../Tasks/Arrays/Length.cs | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Tests/YDotNet.Tests.Driver/Tasks/Arrays/Length.cs diff --git a/Tests/YDotNet.Tests.Driver/Program.cs b/Tests/YDotNet.Tests.Driver/Program.cs index 1a4b2c8d..610f05fb 100644 --- a/Tests/YDotNet.Tests.Driver/Program.cs +++ b/Tests/YDotNet.Tests.Driver/Program.cs @@ -2,4 +2,4 @@ using YDotNet.Tests.Driver.Tasks.Arrays; -new Iterate().Run(); +new Length().Run(); diff --git a/Tests/YDotNet.Tests.Driver/Tasks/Arrays/Length.cs b/Tests/YDotNet.Tests.Driver/Tasks/Arrays/Length.cs new file mode 100644 index 00000000..868f138b --- /dev/null +++ b/Tests/YDotNet.Tests.Driver/Tasks/Arrays/Length.cs @@ -0,0 +1,47 @@ +using YDotNet.Document; +using YDotNet.Document.Cells; +using YDotNet.Tests.Driver.Abstractions; + +namespace YDotNet.Tests.Driver.Tasks.Arrays; + +public class Length : ITask +{ + public Task Run() + { + var count = 0; + + // Create many documents + while (count < 1_000_000) + { + // After 1s, stop and show the user the amount of documents + if (count > 0) + { + Console.WriteLine("Status Report"); + Console.WriteLine($"\tArrays:\t{count}"); + Console.WriteLine(); + } + + if (count % 1_000 == 0) + { + Thread.Sleep(millisecondsTimeout: 15); + } + + // Create many documents + for (var i = 0; i < 100; i++) + { + var doc = new Doc(); + var array = doc.Array($"sample-{i}"); + + var transaction = doc.WriteTransaction(); + array.InsertRange(transaction, index: 0, new[] { Input.Long(value: 2469L) }); + var _ = array.Length; + transaction.Commit(); + + doc.Dispose(); + count++; + } + } + + return Task.CompletedTask; + } +}