Skip to content

Commit

Permalink
[#9] Added BenchmarkDotNet-based tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad-kruczynski committed May 2, 2021
1 parent c37b893 commit 898b180
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions Migrantoid.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions PerformanceTests/PerformanceTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Migrantoid.PerformanceTests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Migrantoid\Migrantoid.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>
</Project>
56 changes: 56 additions & 0 deletions PerformanceTests/PrimitiveReaderWriterTests.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
39 changes: 39 additions & 0 deletions PerformanceTests/Program.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}

0 comments on commit 898b180

Please sign in to comment.