diff --git a/Benchmarks/DualityBenchmarks/CloneProviderBenchmarks.cs b/Benchmarks/DualityBenchmarks/CloneProviderBenchmarks.cs new file mode 100644 index 000000000..ccf86ccfa --- /dev/null +++ b/Benchmarks/DualityBenchmarks/CloneProviderBenchmarks.cs @@ -0,0 +1,34 @@ +using System; +using BenchmarkDotNet.Attributes; +using Duality.Cloning; +using Duality.Tests.Serialization; + +namespace DualityBenchmarks +{ + public class CloneProviderBenchmarks + { + [Benchmark] + public void CloneTestObjectGraph() + { + Random rnd = new Random(0); + TestObject data = new TestObject(rnd, 5); + TestObject[] results = new TestObject[200]; + + for (int i = 0; i < results.Length; i++) + { + results[i] = data.DeepClone(); + } + } + + [Benchmark(Baseline = true)] + public void CreateWithoutClone() + { + Random rnd = new Random(0); + TestObject[] results = new TestObject[200]; + for (int i = 0; i < results.Length; i++) + { + results[i] = new TestObject(rnd, 5); + } + } + } +} \ No newline at end of file diff --git a/Benchmarks/DualityBenchmarks/DualityBenchmarks.csproj b/Benchmarks/DualityBenchmarks/DualityBenchmarks.csproj new file mode 100644 index 000000000..67942ab67 --- /dev/null +++ b/Benchmarks/DualityBenchmarks/DualityBenchmarks.csproj @@ -0,0 +1,17 @@ + + + + Exe + net472 + + + + + + + + + + + + diff --git a/Benchmarks/DualityBenchmarks/Program.cs b/Benchmarks/DualityBenchmarks/Program.cs new file mode 100644 index 000000000..5be4b2096 --- /dev/null +++ b/Benchmarks/DualityBenchmarks/Program.cs @@ -0,0 +1,13 @@ +using System; +using BenchmarkDotNet.Running; + +namespace DualityBenchmarks +{ + class Program + { + static void Main(string[] args) + { + BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); + } + } +} diff --git a/Duality.sln b/Duality.sln index 74528fed4..566c206cc 100644 --- a/Duality.sln +++ b/Duality.sln @@ -102,6 +102,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DualityPhysics", "Source\Co EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DualityTemplates", "Source\DualityTemplates\DualityTemplates.csproj", "{3AB26D57-70D9-40DE-B12D-6B1489035805}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DualityBenchmarks", "Benchmarks\DualityBenchmarks\DualityBenchmarks.csproj", "{20985018-3635-478D-BA4F-6AF1E278C0AB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -260,6 +262,10 @@ Global {3AB26D57-70D9-40DE-B12D-6B1489035805}.Debug|Any CPU.Build.0 = Debug|Any CPU {3AB26D57-70D9-40DE-B12D-6B1489035805}.Release|Any CPU.ActiveCfg = Release|Any CPU {3AB26D57-70D9-40DE-B12D-6B1489035805}.Release|Any CPU.Build.0 = Release|Any CPU + {20985018-3635-478D-BA4F-6AF1E278C0AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {20985018-3635-478D-BA4F-6AF1E278C0AB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {20985018-3635-478D-BA4F-6AF1E278C0AB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {20985018-3635-478D-BA4F-6AF1E278C0AB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -305,6 +311,7 @@ Global {D220795D-8A59-432F-A8EC-CE9143DD07D5} = {9D215950-8E34-4070-914F-7B7D8A54ED6C} {165D83B8-EAE8-4CDC-9003-E595D4225B8F} = {9D215950-8E34-4070-914F-7B7D8A54ED6C} {5CA66347-C3DA-47DA-B07B-E2B89E6E712A} = {FC08D0D6-612E-4AD2-950C-8E9BA895D5D1} + {20985018-3635-478D-BA4F-6AF1E278C0AB} = {FC08D0D6-612E-4AD2-950C-8E9BA895D5D1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {74E2A280-F2F3-400D-9CC2-7A91D6D3D15C} diff --git a/Test/Core/Cloning/CloneProviderTest.cs b/Test/Core/Cloning/CloneProviderTest.cs index 03ac3cea7..eb90fb957 100644 --- a/Test/Core/Cloning/CloneProviderTest.cs +++ b/Test/Core/Cloning/CloneProviderTest.cs @@ -511,37 +511,5 @@ [Test] public void PartialCloning() provider.ClearCachedMapping(); Assert.DoesNotThrow(() => provider.CloneObject(targetStatic3, true)); } - [Test] public void PerformanceTest() - { - Random rnd = new Random(0); - TestObject data = new TestObject(rnd, 5); - TestObject[] results = new TestObject[200]; - - GC.Collect(); - - var watch = new System.Diagnostics.Stopwatch(); - watch.Start(); - for (int i = 0; i < results.Length; i++) - { - results[i] = data.DeepClone(); - } - watch.Stop(); - TestHelper.LogNumericTestResult(this, "CloneTestObjectGraph", watch.Elapsed.TotalMilliseconds, "ms"); - - GC.Collect(); - - var watch2 = new System.Diagnostics.Stopwatch(); - watch2.Start(); - for (int i = 0; i < results.Length; i++) - { - results[i] = new TestObject(rnd, 5); - } - watch2.Stop(); - TestHelper.LogNumericTestResult(this, "CreateWithoutClone", watch2.Elapsed.TotalMilliseconds, "ms"); - TestHelper.LogNumericTestResult(this, "CloneVersusRaw", watch.Elapsed.TotalMilliseconds / watch2.Elapsed.TotalMilliseconds, null); - - GC.Collect(); - Assert.Pass(); - } } }