From bfab813e804be81582508dc94610e4bc23ec44e2 Mon Sep 17 00:00:00 2001 From: Danil Date: Sun, 27 Dec 2020 11:38:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B5=D0=BD=D1=87=D0=BC=D0=B0=D1=80?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Benchmark/Benchmark.sln | 31 +++++++++++++++ Benchmark/Benchmark/Benchmark.csproj | 12 ++++++ Benchmark/Benchmark/EasiestTest.cs | 13 +++++++ Benchmark/Benchmark/Program.cs | 14 +++++++ Benchmark/Benchmark/TestClass.cs | 56 ++++++++++++++++++++++++++++ Benchmark/Tests/Tests.csproj | 15 ++++++++ Benchmark/Tests/UnitTest1.cs | 18 +++++++++ 7 files changed, 159 insertions(+) create mode 100644 Benchmark/Benchmark.sln create mode 100644 Benchmark/Benchmark/Benchmark.csproj create mode 100644 Benchmark/Benchmark/EasiestTest.cs create mode 100644 Benchmark/Benchmark/Program.cs create mode 100644 Benchmark/Benchmark/TestClass.cs create mode 100644 Benchmark/Tests/Tests.csproj create mode 100644 Benchmark/Tests/UnitTest1.cs diff --git a/Benchmark/Benchmark.sln b/Benchmark/Benchmark.sln new file mode 100644 index 0000000..a087298 --- /dev/null +++ b/Benchmark/Benchmark.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30621.155 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "Benchmark\Benchmark.csproj", "{43585CD2-9507-48FC-8A39-325D53A6B2C3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{65A66F13-289C-44A0-BD3D-B00E57753E9F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {43585CD2-9507-48FC-8A39-325D53A6B2C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43585CD2-9507-48FC-8A39-325D53A6B2C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43585CD2-9507-48FC-8A39-325D53A6B2C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43585CD2-9507-48FC-8A39-325D53A6B2C3}.Release|Any CPU.Build.0 = Release|Any CPU + {65A66F13-289C-44A0-BD3D-B00E57753E9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {65A66F13-289C-44A0-BD3D-B00E57753E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65A66F13-289C-44A0-BD3D-B00E57753E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {65A66F13-289C-44A0-BD3D-B00E57753E9F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {50156758-2800-4502-AE2B-0A243EDDFBEE} + EndGlobalSection +EndGlobal diff --git a/Benchmark/Benchmark/Benchmark.csproj b/Benchmark/Benchmark/Benchmark.csproj new file mode 100644 index 0000000..1d9085a --- /dev/null +++ b/Benchmark/Benchmark/Benchmark.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/Benchmark/Benchmark/EasiestTest.cs b/Benchmark/Benchmark/EasiestTest.cs new file mode 100644 index 0000000..cfd0669 --- /dev/null +++ b/Benchmark/Benchmark/EasiestTest.cs @@ -0,0 +1,13 @@ +using BenchmarkDotNet.Running; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Benchmark +{ + class EasiestTest + { + public static void OnTestsStart() => + BenchmarkRunner.Run(); + } +} diff --git a/Benchmark/Benchmark/Program.cs b/Benchmark/Benchmark/Program.cs new file mode 100644 index 0000000..8a4d110 --- /dev/null +++ b/Benchmark/Benchmark/Program.cs @@ -0,0 +1,14 @@ +using System; + +namespace Benchmark +{ + class Program + { + static void Main(string[] args) + { + EasiestTest.OnTestsStart(); + + Console.ReadKey(); + } + } +} diff --git a/Benchmark/Benchmark/TestClass.cs b/Benchmark/Benchmark/TestClass.cs new file mode 100644 index 0000000..96a8b79 --- /dev/null +++ b/Benchmark/Benchmark/TestClass.cs @@ -0,0 +1,56 @@ +using System; +using BenchmarkDotNet; +using System.Text; +using BenchmarkDotNet.Attributes; + +namespace Benchmark +{ + class TestClass + { + void SimulateWork() + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 10000; i++) + builder.Append(i.ToString()); + } + + public static void PbStaticVoid() + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 10000; i++) + builder.Append(i.ToString()); + } + + [Benchmark(Description = "PbVoid")] + public void PbVoid() => + SimulateWork(); + + [Benchmark(Description = "PbVirtualVoid")] + public virtual void PbVirtualVoid() => + SimulateWork(); + + public static void PbGenericStaticVoid() + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 10000; i++) + builder.Append(i.ToString()); + } + + public static void PbGenericStaticVoid() => + PbGenericStaticVoid(); + + + [Benchmark(Description = "PbGenericVoid")] + public void PbGenericVoid() => + SimulateWork(); + + [Benchmark(Description = "PbDynamic")] + public dynamic PbDynamic() + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 10000; i++) + builder.Append(i.ToString()); + return builder; + } + } +} diff --git a/Benchmark/Tests/Tests.csproj b/Benchmark/Tests/Tests.csproj new file mode 100644 index 0000000..43f0ccc --- /dev/null +++ b/Benchmark/Tests/Tests.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + diff --git a/Benchmark/Tests/UnitTest1.cs b/Benchmark/Tests/UnitTest1.cs new file mode 100644 index 0000000..794c408 --- /dev/null +++ b/Benchmark/Tests/UnitTest1.cs @@ -0,0 +1,18 @@ +using NUnit.Framework; + +namespace Tests +{ + public class Tests + { + [SetUp] + public void Setup() + { + } + + [Test] + public void Test1() + { + Assert.Pass(); + } + } +} \ No newline at end of file