diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 9cd21d1..582ca23 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -15,3 +15,6 @@ jobs: dotnet-version: 5.0.202 - name: Unit tests run: dotnet test Tests/Tests.csproj + - name: Performance tests + working-directory: ./PerformanceTests + run: dotnet run --configuration Release \ No newline at end of file diff --git a/.gitignore b/.gitignore index ddcaa1c..db69345 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ obj #packages packages .vs +BenchmarkDotNet.Artifacts diff --git a/Migrantoid.sln b/Migrantoid.sln index 741ba67..a0094c3 100644 --- a/Migrantoid.sln +++ b/Migrantoid.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsSecondModule", "Second EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{D8B97D5B-6657-4E61-8100-159F73AB5123}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerformanceTests", "PerformanceTests\PerformanceTests.csproj", "{74491C56-5FF1-4412-A454-60A4196EE8EB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {D8B97D5B-6657-4E61-8100-159F73AB5123}.Debug|Any CPU.Build.0 = Debug|Any CPU {D8B97D5B-6657-4E61-8100-159F73AB5123}.Release|Any CPU.ActiveCfg = Release|Any CPU {D8B97D5B-6657-4E61-8100-159F73AB5123}.Release|Any CPU.Build.0 = Release|Any CPU + {74491C56-5FF1-4412-A454-60A4196EE8EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74491C56-5FF1-4412-A454-60A4196EE8EB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74491C56-5FF1-4412-A454-60A4196EE8EB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74491C56-5FF1-4412-A454-60A4196EE8EB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PerformanceTests/PerformanceTests.csproj b/PerformanceTests/PerformanceTests.csproj new file mode 100644 index 0000000..ff5ac94 --- /dev/null +++ b/PerformanceTests/PerformanceTests.csproj @@ -0,0 +1,15 @@ + + + + Exe + net5.0 + Migrantoid.PerformanceTests + + + + + + + + + diff --git a/PerformanceTests/PrimitiveReaderWriterTests.cs b/PerformanceTests/PrimitiveReaderWriterTests.cs new file mode 100644 index 0000000..f43d894 --- /dev/null +++ b/PerformanceTests/PrimitiveReaderWriterTests.cs @@ -0,0 +1,56 @@ +// ******************************************************************* +// +// Copyright (c) 2021 Konrad Kruczyński +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ******************************************************************* + +using System; +using System.IO; +using BenchmarkDotNet.Attributes; + +namespace Migrantoid.PerformanceTests +{ + public class PrimitiveReaderWriterTests + { + public PrimitiveReaderWriterTests() + { + var random = new Random(1234); + IntSource = new int[1024 * 1024 * 100]; + for (var i = 0; i < IntSource.Length; i++) + { + IntSource[i] = random.Next(); + } + } + + [Benchmark] + public void IntSerializationTest() + { + var primitiveWriter = new PrimitiveWriter(Stream.Null); + for (var i = 0; i < IntSource.Length; i++) + { + primitiveWriter.Write(i); + } + } + + private readonly int[] IntSource; + } +} diff --git a/PerformanceTests/Program.cs b/PerformanceTests/Program.cs new file mode 100644 index 0000000..4055468 --- /dev/null +++ b/PerformanceTests/Program.cs @@ -0,0 +1,39 @@ +// ******************************************************************* +// +// Copyright (c) 2021 Konrad Kruczyński +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ******************************************************************* + +using System; +using System.Reflection; +using BenchmarkDotNet.Running; + +namespace Migrantoid.PerformanceTests +{ + public class Program + { + static void Main(string[] args) + { + BenchmarkRunner.Run(Assembly.GetExecutingAssembly()); + } + } +}