Skip to content

Commit

Permalink
add .netcore 2.0 tester
Browse files Browse the repository at this point in the history
  • Loading branch information
00raq00 committed Sep 16, 2017
1 parent 784cc32 commit 6536d51
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 7 deletions.
Binary file modified .vs/StructsVsObjects/v15/.suo
Binary file not shown.
Binary file modified .vs/StructsVsObjects/v15/sqlite3/storage.ide
Binary file not shown.
2 changes: 2 additions & 0 deletions Runner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ static void Main(string[] args)
// memory usage of the process.
memoryTester("StructsVsObjects.exe", "Class");
memoryTester("StructsVsObjects.exe", "Struct");
memoryTester("dotnet", "netcoreapp2.0\\StructsVsObjectsCore.dll Class");
memoryTester("dotnet", "netcoreapp2.0\\StructsVsObjectsCore.dll Struct");

Console.ReadKey();
}
Expand Down
20 changes: 20 additions & 0 deletions Runner/Runner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
22 changes: 18 additions & 4 deletions StructsVsObjects.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructsVsObjects", "StructsVsObjects\StructsVsObjects.csproj", "{BEA29F4F-D10B-436E-9320-DD16CE79B783}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Runner", "Runner\Runner.csproj", "{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}"
ProjectSection(ProjectDependencies) = postProject
{BEA29F4F-D10B-436E-9320-DD16CE79B783} = {BEA29F4F-D10B-436E-9320-DD16CE79B783}
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD} = {6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructsVsObjectsCore", "StructsVsObjectsCore\StructsVsObjectsCore.csproj", "{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -19,8 +25,8 @@ Global
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Debug|x64.ActiveCfg = Debug|x64
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Debug|x64.Build.0 = Debug|x64
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Release|Any CPU.Build.0 = Debug|Any CPU
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Release|Any CPU.Build.0 = Release|Any CPU
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Release|x64.ActiveCfg = Release|x64
{BEA29F4F-D10B-436E-9320-DD16CE79B783}.Release|x64.Build.0 = Release|x64
{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -29,8 +35,16 @@ Global
{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}.Debug|x64.Build.0 = Debug|Any CPU
{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}.Release|Any CPU.Build.0 = Release|Any CPU
{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}.Release|x64.ActiveCfg = Release|Any CPU
{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}.Release|x64.Build.0 = Release|Any CPU
{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}.Release|x64.ActiveCfg = Release|x64
{A807CCB7-F47E-4197-9A20-BBC597FC1E1C}.Release|x64.Build.0 = Release|x64
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}.Debug|x64.ActiveCfg = Debug|Any CPU
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}.Debug|x64.Build.0 = Debug|Any CPU
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}.Release|Any CPU.Build.0 = Release|Any CPU
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}.Release|x64.ActiveCfg = Release|x64
{6A99975A-C2E3-4D8C-A3DB-3A5D1EB6D4FD}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions StructsVsObjects/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main(string[] args)
{
int readedValue = int.MaxValue / 300;

if (args[0].Equals("Class"))
if (args.Length==0 || string.IsNullOrEmpty(args[0]) || args[0].Equals("Class"))
{

GC.Collect(GC.MaxGeneration);
Expand All @@ -26,7 +26,7 @@ static void Main(string[] args)
Console.WriteLine(ClassStatic.SampleClass(readedValue, 30));

}
else if (args[0].Equals("Struct"))
if (args.Length == 0 || string.IsNullOrEmpty(args[0]) || args[0].Equals("Struct"))
{

// Console.ReadKey();
Expand Down
2 changes: 1 addition & 1 deletion StructsVsObjects/SampleStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct SampleStruct
internal int j;
internal int z;

public SampleStruct(int i, int j, int z)
public SampleStruct(int i, int j, int z)
{
this.i = i;
this.j = j;
Expand Down
1 change: 1 addition & 0 deletions StructsVsObjects/StructsVsObjects.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ISampleStruct.cs" />
<Compile Include="StructStatic.cs" />
<Compile Include="ClassStatic.cs" />
<Compile Include="Program.cs" />
Expand Down
142 changes: 142 additions & 0 deletions StructsVsObjectsCore/ClassStatic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using StructsVsObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClasssVsObjects
{
public static class ClassStatic
{
static bool logMemory = false;
static bool logTimeInternal = false;
public static int SampleClass(int readedValue)
{
int ss = 0;
Process currentProc;
long memory, memory2;
unchecked
{
currentProc = Process.GetCurrentProcess();
memory = GC.GetTotalMemory(true);
memory2 = currentProc.WorkingSet64;
if (logMemory)
{
Console.WriteLine($"memory before {memory}");
Console.WriteLine($"memory before {memory2}");
}

{
SampleClass[] sampleClass = new SampleClass[readedValue];
for (int i = 0; i < readedValue; i++)
{
sampleClass[i] = new SampleClass(i, i * 2, i * 3);

}


int[] tmp = new int[readedValue];

var sw = Stopwatch.StartNew();

for (int i = 0; i < readedValue; i++)
{
tmp[i] = AddClass(sampleClass[i]);
}


for (int i = 0; i < tmp.Length; i++)
ss += tmp[i];
if (logTimeInternal)
{
Console.WriteLine($"{ss} {sw.Elapsed}");
}

Process currentProc2 = Process.GetCurrentProcess();
long memory12 = GC.GetTotalMemory(true);
long memory22 = currentProc2.WorkingSet64;
if (logMemory)
{
Console.WriteLine($"memory in Class {memory12}");
Console.WriteLine($"memory in Class {memory22}");
}
}

currentProc = Process.GetCurrentProcess();
memory = GC.GetTotalMemory(true);
memory2 = currentProc.WorkingSet64;
if (logMemory)
{
Console.WriteLine($"memory after Class {memory}");
Console.WriteLine($"memory after Class {memory2}");
}
}
return ss;
}

public static int SampleClass(int readedValue, int count, bool logMemoryInternal = false, bool logTimeInternal = false)
{

var currentProc = Process.GetCurrentProcess();
currentProc.Refresh();
var gcMemoryBefore = GC.GetTotalMemory(true);
var memoryBefore = currentProc.WorkingSet64;


logMemory = logMemoryInternal;
ClassStatic.logTimeInternal = logTimeInternal;
var sw = Stopwatch.StartNew();
int val = 0;
for (int i = 0; i < count; i++)
{
val += SampleClass(readedValue);
}
Console.WriteLine($"SampleClass(int readedValue, int count) {sw.Elapsed}");

var currentProc1 = Process.GetCurrentProcess();
currentProc1.Refresh();
var gcMemoryAfter = GC.GetTotalMemory(true);
var memoryAfter = currentProc1.WorkingSet64;

Console.WriteLine($"SampleClass(int readedValue, int count) MEMORY {memoryAfter- memoryBefore}, GC MEMORY {gcMemoryAfter- gcMemoryBefore}");


Console.WriteLine(" physical memory usage: {0}",
currentProc1.WorkingSet64);
Console.WriteLine(" base priority: {0}",
currentProc1.BasePriority);
Console.WriteLine(" priority class: {0}",
currentProc1.PriorityClass);
Console.WriteLine(" user processor time: {0}",
currentProc1.UserProcessorTime);
Console.WriteLine(" privileged processor time: {0}",
currentProc1.PrivilegedProcessorTime);
Console.WriteLine(" total processor time: {0}",
currentProc1.TotalProcessorTime);
Console.WriteLine(" PagedSystemMemorySize64: {0}",
currentProc1.PagedSystemMemorySize64);
Console.WriteLine(" PagedMemorySize64: {0}",
currentProc1.PagedMemorySize64);

// Update the values for the overall peak memory statistics.
Console.WriteLine(" PeakPagedMemorySize64: {0}", currentProc1.PeakPagedMemorySize64);
Console.WriteLine(" PeakVirtualMemorySize64: {0}", currentProc1.PeakVirtualMemorySize64);
Console.WriteLine(" PeakWorkingSet64: {0}", currentProc1.PeakWorkingSet64);

return val;
}


public static int AddClass(SampleClass cl)
{
if (cl.z < 100)
return cl.i + cl.j + cl.z;
else
{
return cl.i % 1000;
}
}
}
}
42 changes: 42 additions & 0 deletions StructsVsObjectsCore/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using ClasssVsObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StructsVsObjects
{
static class Program
{
static void Main(string[] args)
{
unchecked
{
int readedValue = int.MaxValue / 300;

if (args.Length==0 || string.IsNullOrEmpty(args[0]) || args[0].Equals("Class"))
{

GC.Collect(GC.MaxGeneration);
GC.WaitForFullGCComplete();


Console.WriteLine(ClassStatic.SampleClass(readedValue, 30));

}
if (args.Length == 0 || string.IsNullOrEmpty(args[0]) || args[0].Equals("Struct"))
{

// Console.ReadKey();
GC.Collect(GC.MaxGeneration);
GC.WaitForFullGCComplete();

Console.WriteLine(StructStatic.SampleStruct(readedValue, 30));
}

}
}
}
}
22 changes: 22 additions & 0 deletions StructsVsObjectsCore/SampleClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StructsVsObjects
{
public class SampleClass
{
internal int i;
internal int j;
internal int z;

public SampleClass(int i, int j, int z)
{
this.i = i;
this.j = j;
this.z = z;
}
}
}
22 changes: 22 additions & 0 deletions StructsVsObjectsCore/SampleStruct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StructsVsObjects
{
public struct SampleStruct
{
internal int i;
internal int j;
internal int z;

public SampleStruct(int i, int j, int z)
{
this.i = i;
this.j = j;
this.z = z;
}
}
}
Loading

0 comments on commit 6536d51

Please sign in to comment.