From 16cb7509e731d29b5b72ca0bb6f5dd416a4a596c Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 6 Jun 2017 21:26:29 +0200 Subject: [PATCH] Added MemoryLeakTest (#87) --- System.Linq.Dynamic.Core.sln | 17 ++++- src-console/MemoryLeakTest/App.config | 6 ++ .../MemoryLeakTest/MemoryLeakTest.csproj | 72 +++++++++++++++++++ src-console/MemoryLeakTest/Person.cs | 15 ++++ src-console/MemoryLeakTest/Pet.cs | 19 +++++ src-console/MemoryLeakTest/Program.cs | 16 +++++ .../MemoryLeakTest/Properties/AssemblyInfo.cs | 36 ++++++++++ src-console/MemoryLeakTest/Test.cs | 72 +++++++++++++++++++ src-console/MemoryLeakTest/Toy.cs | 17 +++++ 9 files changed, 269 insertions(+), 1 deletion(-) create mode 100644 src-console/MemoryLeakTest/App.config create mode 100644 src-console/MemoryLeakTest/MemoryLeakTest.csproj create mode 100644 src-console/MemoryLeakTest/Person.cs create mode 100644 src-console/MemoryLeakTest/Pet.cs create mode 100644 src-console/MemoryLeakTest/Program.cs create mode 100644 src-console/MemoryLeakTest/Properties/AssemblyInfo.cs create mode 100644 src-console/MemoryLeakTest/Test.cs create mode 100644 src-console/MemoryLeakTest/Toy.cs diff --git a/System.Linq.Dynamic.Core.sln b/System.Linq.Dynamic.Core.sln index 470f7251..a4a53f91 100644 --- a/System.Linq.Dynamic.Core.sln +++ b/System.Linq.Dynamic.Core.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26403.0 +VisualStudioVersion = 15.0.26430.12 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8463ED7E-69FB-49AE-85CF-0791AFD98E38}" EndProject @@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Linq.Dynamic.Core.Co EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test-uap", "test-uap", "{ECA5702B-5D32-4888-A34E-9461FC533F23}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MemoryLeakTest", "src-console\MemoryLeakTest\MemoryLeakTest.csproj", "{DE991A5E-575C-4B0F-B93D-6D283E5928D6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -217,6 +219,18 @@ Global {467B5A08-2A38-45B6-BC29-4C013B280448}.Release|x64.Build.0 = Release|Any CPU {467B5A08-2A38-45B6-BC29-4C013B280448}.Release|x86.ActiveCfg = Release|Any CPU {467B5A08-2A38-45B6-BC29-4C013B280448}.Release|x86.Build.0 = Release|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Debug|x64.ActiveCfg = Debug|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Debug|x64.Build.0 = Debug|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Debug|x86.ActiveCfg = Debug|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Debug|x86.Build.0 = Debug|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Release|Any CPU.Build.0 = Release|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Release|x64.ActiveCfg = Release|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Release|x64.Build.0 = Release|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Release|x86.ActiveCfg = Release|Any CPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -235,5 +249,6 @@ Global {4E96C457-E09D-4ACB-BAD0-C0E154B78B27} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62} {0EB12661-F5CF-4071-9812-F4C8AF3D4531} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62} {467B5A08-2A38-45B6-BC29-4C013B280448} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62} + {DE991A5E-575C-4B0F-B93D-6D283E5928D6} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F} EndGlobalSection EndGlobal diff --git a/src-console/MemoryLeakTest/App.config b/src-console/MemoryLeakTest/App.config new file mode 100644 index 00000000..88fa4027 --- /dev/null +++ b/src-console/MemoryLeakTest/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src-console/MemoryLeakTest/MemoryLeakTest.csproj b/src-console/MemoryLeakTest/MemoryLeakTest.csproj new file mode 100644 index 00000000..88f358f8 --- /dev/null +++ b/src-console/MemoryLeakTest/MemoryLeakTest.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {DE991A5E-575C-4B0F-B93D-6D283E5928D6} + Exe + Properties + MemoryLeakTest + MemoryLeakTest + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + ..\packages\System.Linq.Dynamic.1.0.7\lib\net40\System.Linq.Dynamic.dll + True + + + ..\..\src\System.Linq.Dynamic.Core\bin\Release\net35\System.Linq.Dynamic.Core.dll + True + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src-console/MemoryLeakTest/Person.cs b/src-console/MemoryLeakTest/Person.cs new file mode 100644 index 00000000..9d23295a --- /dev/null +++ b/src-console/MemoryLeakTest/Person.cs @@ -0,0 +1,15 @@ +using System; + +namespace MemoryLeakTest +{ + public class Person + { + public Guid Id; + + public string Name; + + public int From; + + public int Till; + } +} \ No newline at end of file diff --git a/src-console/MemoryLeakTest/Pet.cs b/src-console/MemoryLeakTest/Pet.cs new file mode 100644 index 00000000..49254d1d --- /dev/null +++ b/src-console/MemoryLeakTest/Pet.cs @@ -0,0 +1,19 @@ +using System; + +namespace MemoryLeakTest +{ + public class Pet + { + public Guid Id; + + public string Name; + + public Person Owner; + + public Guid OwnerId { get { return Owner.Id; } } + + public int From; + + public int Till; + } +} \ No newline at end of file diff --git a/src-console/MemoryLeakTest/Program.cs b/src-console/MemoryLeakTest/Program.cs new file mode 100644 index 00000000..f1ac71b7 --- /dev/null +++ b/src-console/MemoryLeakTest/Program.cs @@ -0,0 +1,16 @@ +using System; + +namespace MemoryLeakTest +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("press key to run"); + Console.ReadKey(); + + Test t = new Test(); + t.Join(); + } + } +} \ No newline at end of file diff --git a/src-console/MemoryLeakTest/Properties/AssemblyInfo.cs b/src-console/MemoryLeakTest/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..75795d6a --- /dev/null +++ b/src-console/MemoryLeakTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MemoryLeakTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MemoryLeakTest")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("de991a5e-575c-4b0f-b93d-6d283e5928d6")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src-console/MemoryLeakTest/Test.cs b/src-console/MemoryLeakTest/Test.cs new file mode 100644 index 00000000..bf862b69 --- /dev/null +++ b/src-console/MemoryLeakTest/Test.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Linq.Dynamic.Core; + +namespace MemoryLeakTest +{ + public class Test + { + public void Join() + { + //Arrange + Person magnus = new Person { Id = Guid.NewGuid(), Name = "Hedlund, Magnus", From = 100, Till = 1000 }; + Person terry = new Person { Id = Guid.NewGuid(), Name = "Adams, Terry", From = 10230, Till = 100440 }; + Person charlotte = new Person { Id = Guid.NewGuid(), Name = "Weiss, Charlotte", From = 10, Till = 154 }; + + Pet barley = new Pet { Id = Guid.NewGuid(), Name = "Barley", Owner = terry, From = 67, Till = 231 }; + Pet boots = new Pet { Id = Guid.NewGuid(), Name = "Boots", Owner = terry, From = 120, Till = 220 }; + Pet whiskers = new Pet { Id = Guid.NewGuid(), Name = "Whiskers", Owner = charlotte, From = 3310, Till = 9010 }; + Pet daisy = new Pet { Id = Guid.NewGuid(), Name = "Daisy", Owner = magnus, From = 27, Till = 1200 }; + + Toy ball1 = new Toy { Id = Guid.NewGuid(), From = 10, Till = 200, Pet = barley }; + Toy ball2 = new Toy { Id = Guid.NewGuid(), From = 89, Pet = barley, Till = 348 }; + Toy duck1 = new Toy { Id = Guid.NewGuid(), From = 10, Till = 200, Pet = boots }; + Toy duck2 = new Toy { Id = Guid.NewGuid(), From = 89, Pet = whiskers, Till = 348 }; + Toy toy1 = new Toy { Id = Guid.NewGuid(), From = 10, Till = 200, Pet = boots }; + Toy toy2 = new Toy { Id = Guid.NewGuid(), From = 89, Pet = daisy, Till = 348 }; + Toy something1 = new Toy { Id = Guid.NewGuid(), From = 10, Till = 200, Pet = daisy }; + Toy something2 = new Toy { Id = Guid.NewGuid(), From = 89, Pet = barley, Till = 348 }; + Toy toy3 = new Toy { Id = Guid.NewGuid(), From = 10, Till = 200, Pet = daisy }; + Toy toy4 = new Toy { Id = Guid.NewGuid(), From = 89, Pet = whiskers, Till = 348 }; + + + IList people = new List { magnus, terry, charlotte }; + IList pets = new List { barley, boots, whiskers, daisy }; + IList toys = new List { ball1, ball2, duck1, duck2, toy1, toy2, something1, something2, toy3, toy4 }; + + //Act + var sw = new Stopwatch(); + long t = 0; + var rnd = new Random(); + for (var i = 0; i < 400; i++) + { + sw.Start(); + Act(people, pets, toys, rnd); + sw.Stop(); + t = sw.ElapsedMilliseconds; + if (i % 10 == 0) + { + Console.WriteLine("{0} - {1}", i, t); + } + sw.Reset(); + } + } + + private dynamic[] Act(IList people, IList pets, IList toys, Random rnd) + { + var peopleQ = people.AsQueryable().Where(string.Format("From<{0} AND Till>{1}", rnd.Next(0, 500), rnd.Next(500, 20000))); + var petsQ = pets.AsQueryable().Where(string.Format("From<{0} AND Till>{1}", rnd.Next(0, 500), rnd.Next(500, 20000))); + var toyQ = toys.AsQueryable().Where(string.Format("From<{0} AND Till>{1}", rnd.Next(0, 500), rnd.Next(500, 20000))); + + var q1 = petsQ.Join(toyQ, "new (Id as firstKey)", "new (PetId as firstKey)", "new (inner as toy, outer as pet)"); + var q2 = peopleQ.Join(q1, "new (Id as firstKey)", "new (pet.OwnerId as firstKey)", "new (inner as pet, outer as person)") + .Select("new (person.Name as personName, pet.pet.Name as petName, pet.toy.Id as toyUid)"); + + var result = q2.ToDynamicArray(); + return result; + } + } +} \ No newline at end of file diff --git a/src-console/MemoryLeakTest/Toy.cs b/src-console/MemoryLeakTest/Toy.cs new file mode 100644 index 00000000..b93e7e4c --- /dev/null +++ b/src-console/MemoryLeakTest/Toy.cs @@ -0,0 +1,17 @@ +using System; + +namespace MemoryLeakTest +{ + public class Toy + { + public Guid Id; + + public int From; + + public int Till; + + public Pet Pet; + + public Guid PetId { get { return Pet.Id; } } + } +} \ No newline at end of file