Skip to content

Commit

Permalink
Added MemoryLeakTest (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Jun 6, 2017
1 parent ea62a37 commit 16cb750
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 1 deletion.
17 changes: 16 additions & 1 deletion System.Linq.Dynamic.Core.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
6 changes: 6 additions & 0 deletions src-console/MemoryLeakTest/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
72 changes: 72 additions & 0 deletions src-console/MemoryLeakTest/MemoryLeakTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DE991A5E-575C-4B0F-B93D-6D283E5928D6}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MemoryLeakTest</RootNamespace>
<AssemblyName>MemoryLeakTest</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Linq.Dynamic, Version=1.0.6132.35681, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\System.Linq.Dynamic.1.0.7\lib\net40\System.Linq.Dynamic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Linq.Dynamic.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=0f07ec44de6ac832, processorArchitecture=MSIL">
<HintPath>..\..\src\System.Linq.Dynamic.Core\bin\Release\net35\System.Linq.Dynamic.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Person.cs" />
<Compile Include="Pet.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Test.cs" />
<Compile Include="Toy.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
15 changes: 15 additions & 0 deletions src-console/MemoryLeakTest/Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace MemoryLeakTest
{
public class Person
{
public Guid Id;

public string Name;

public int From;

public int Till;
}
}
19 changes: 19 additions & 0 deletions src-console/MemoryLeakTest/Pet.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 16 additions & 0 deletions src-console/MemoryLeakTest/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
36 changes: 36 additions & 0 deletions src-console/MemoryLeakTest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
72 changes: 72 additions & 0 deletions src-console/MemoryLeakTest/Test.cs
Original file line number Diff line number Diff line change
@@ -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<Person> { magnus, terry, charlotte };
IList pets = new List<Pet> { barley, boots, whiskers, daisy };
IList toys = new List<Toy> { 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;
}
}
}
17 changes: 17 additions & 0 deletions src-console/MemoryLeakTest/Toy.cs
Original file line number Diff line number Diff line change
@@ -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; } }
}
}

0 comments on commit 16cb750

Please sign in to comment.