Skip to content

Commit e167c7c

Browse files
committed
Add initial benchmarks
1 parent 9912392 commit e167c7c

9 files changed

+179
-0
lines changed

.github/workflows/build.yml

+22
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,28 @@ jobs:
282282
cd Tests
283283
../../tools/dotnet-stryker -f ../.github/stryker/Stryker.Config.Compression.json -v "${GITHUB_REF#refs/heads/}" -r "Dashboard" -r "cleartext"
284284
285+
benchmark:
286+
name: Run Benchmarks
287+
runs-on: ubuntu-latest
288+
steps:
289+
- uses: actions/checkout@v4
290+
- uses: actions/setup-dotnet@v3
291+
with:
292+
dotnet-version: 8.0.x
293+
- name: Run benchmark
294+
run: cd Tests/Benchmarks/Testably.Abstractions.Benchmarks && dotnet run -c Release --framework net8.0 --exporters json --filter '*'
295+
- name: Store benchmark result
296+
uses: rhysd/github-action-benchmark@v1
297+
with:
298+
name: Benchmark.Net Benchmark
299+
tool: 'benchmarkdotnet'
300+
output-file-path: Tests/Benchmarks/Testably.Abstractions.Benchmarks/BenchmarkDotNet.Artifacts/results/Testably.Abstractions.Benchmarks-report-full-compressed.json
301+
github-token: ${{ secrets.GITHUB_TOKEN }}
302+
auto-push: true
303+
alert-threshold: '150%'
304+
comment-on-alert: false
305+
fail-on-alert: false
306+
285307
deploy:
286308
name: Deploy
287309
if: startsWith(github.ref, 'refs/heads/release/')

.github/workflows/ci.yml

+22
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,25 @@ jobs:
295295
-H "Authorization: token $GITHUB_TOKEN" \
296296
-d "$body"
297297
fi
298+
299+
benchmark:
300+
name: Run Benchmarks
301+
runs-on: ubuntu-latest
302+
steps:
303+
- uses: actions/checkout@v4
304+
- uses: actions/setup-dotnet@v3
305+
with:
306+
dotnet-version: 8.0.x
307+
- name: Run benchmark
308+
run: cd Tests/Benchmarks/Testably.Abstractions.Benchmarks && dotnet run -c Release --framework net8.0 --exporters json --filter '*'
309+
- name: Store benchmark result
310+
uses: rhysd/github-action-benchmark@v1
311+
with:
312+
name: Benchmark.Net Benchmark
313+
tool: 'benchmarkdotnet'
314+
output-file-path: Tests/Benchmarks/Testably.Abstractions.Benchmarks/BenchmarkDotNet.Artifacts/results/Testably.Abstractions.Benchmarks-report-full-compressed.json
315+
github-token: ${{ secrets.GITHUB_TOKEN }}
316+
auto-push: false
317+
alert-threshold: '150%'
318+
comment-on-alert: true
319+
fail-on-alert: true

Directory.Packages.props

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
88
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
99
<PackageVersion Include="TestableIO.System.IO.Abstractions" Version="21.0.2" />
10+
<PackageVersion Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="21.0.2" />
1011
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
1112
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
1213
</ItemGroup>
@@ -32,6 +33,7 @@
3233
<PackageVersion Include="NUnit" Version="4.1.0" />
3334
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0" />
3435
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
36+
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12" />
3537
</ItemGroup>
3638
<ItemGroup>
3739
<PackageVersion Include="Testably.Abstractions" Version="3.2.0" />

Testably.Abstractions.sln

+10
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testably.Abstractions.TestS
100100
EndProject
101101
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Settings", "Settings", "{D32170F4-1455-4839-8EF4-9530F3AA642A}"
102102
EndProject
103+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{500E38FD-F587-4CC7-A7CE-10DA4AC76CE1}"
104+
EndProject
105+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testably.Abstractions.Benchmarks", "Tests\Benchmarks\Testably.Abstractions.Benchmarks\Testably.Abstractions.Benchmarks.csproj", "{459BB7E6-67C5-4C7B-99A8-09AD7D4CAE0C}"
106+
EndProject
103107
Global
104108
GlobalSection(SolutionConfigurationPlatforms) = preSolution
105109
Debug|Any CPU = Debug|Any CPU
@@ -162,6 +166,10 @@ Global
162166
{241E6413-819C-4B06-A739-4D10C2A81365}.Debug|Any CPU.Build.0 = Debug|Any CPU
163167
{241E6413-819C-4B06-A739-4D10C2A81365}.Release|Any CPU.ActiveCfg = Release|Any CPU
164168
{241E6413-819C-4B06-A739-4D10C2A81365}.Release|Any CPU.Build.0 = Release|Any CPU
169+
{459BB7E6-67C5-4C7B-99A8-09AD7D4CAE0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
170+
{459BB7E6-67C5-4C7B-99A8-09AD7D4CAE0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
171+
{459BB7E6-67C5-4C7B-99A8-09AD7D4CAE0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
172+
{459BB7E6-67C5-4C7B-99A8-09AD7D4CAE0C}.Release|Any CPU.Build.0 = Release|Any CPU
165173
EndGlobalSection
166174
GlobalSection(SolutionProperties) = preSolution
167175
HideSolutionNode = FALSE
@@ -186,6 +194,8 @@ Global
186194
{0AEBB1A6-07D6-46DC-BC78-9771D380EBC0} = {2FDB2AAE-E5CE-483E-A1A6-EC0B0A4AD67B}
187195
{241E6413-819C-4B06-A739-4D10C2A81365} = {D32170F4-1455-4839-8EF4-9530F3AA642A}
188196
{D32170F4-1455-4839-8EF4-9530F3AA642A} = {61F335A6-9CE0-4040-A34F-E70B1A55077D}
197+
{500E38FD-F587-4CC7-A7CE-10DA4AC76CE1} = {61F335A6-9CE0-4040-A34F-E70B1A55077D}
198+
{459BB7E6-67C5-4C7B-99A8-09AD7D4CAE0C} = {500E38FD-F587-4CC7-A7CE-10DA4AC76CE1}
189199
EndGlobalSection
190200
GlobalSection(ExtensibilityGlobals) = postSolution
191201
SolutionGuid = {EC4D8481-B9FD-41B5-832A-369210993DF4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using BenchmarkDotNet.Attributes;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.IO.Abstractions;
5+
using System.IO.Abstractions.TestingHelpers;
6+
using System.Linq;
7+
using Testably.Abstractions.Testing;
8+
using Testably.Abstractions.Testing.Initializer;
9+
using MockFileSystem = Testably.Abstractions.Testing.MockFileSystem;
10+
11+
namespace Testably.Abstractions.Benchmarks;
12+
13+
[RPlotExporter]
14+
[MemoryDiagnoser]
15+
public class ConstructorBenchmarks
16+
{
17+
private readonly Dictionary<string, string> _testData = CreateTestData();
18+
19+
public static Dictionary<string, string> CreateTestData()
20+
{
21+
int filesCount = 1000;
22+
int maxDirectoryDepth = 8;
23+
return Enumerable.Range(0, filesCount)
24+
.ToDictionary(
25+
i => @$"C:\{string.Join(@"\", Enumerable.Range(0, (i % maxDirectoryDepth) + 1).Select(j => j.ToString(CultureInfo.InvariantCulture)))}\{i}.bin",
26+
i => i.ToString(CultureInfo.InvariantCulture));
27+
}
28+
29+
[Benchmark]
30+
public IFileSystem TestableIO_1000()
31+
=> new System.IO.Abstractions.TestingHelpers.MockFileSystem(
32+
_testData.ToDictionary(x => x.Key, x => new MockFileData(x.Value)));
33+
34+
[Benchmark]
35+
public IFileSystem TestableIO_Empty()
36+
=> new System.IO.Abstractions.TestingHelpers.MockFileSystem();
37+
38+
[Benchmark]
39+
public IFileSystem Testably_1000() => new MockFileSystem().Initialize()
40+
.With(_testData.Select(x => new FileDescription(x.Key, x.Value)).ToArray()).FileSystem;
41+
42+
[Benchmark]
43+
public IFileSystem Testably_Empty() => new MockFileSystem();
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using BenchmarkDotNet.Attributes;
2+
using System.IO.Abstractions;
3+
using MockFileSystem = Testably.Abstractions.Testing.MockFileSystem;
4+
5+
namespace Testably.Abstractions.Benchmarks;
6+
7+
[RPlotExporter]
8+
[MemoryDiagnoser]
9+
public class CreateDirectoryBenchmarks
10+
{
11+
private readonly string DirectoryPath = @"C:\l1\l2\l3\l4\l5\l6\l7\l8\l9\l10";
12+
13+
private readonly IFileSystem SystemIOFileSystem =
14+
new System.IO.Abstractions.TestingHelpers.MockFileSystem();
15+
16+
private readonly IFileSystem TestablyFileSystem = new MockFileSystem();
17+
18+
[Benchmark]
19+
public void TestableIO_CreateDirectory()
20+
=> SystemIOFileSystem.Directory.CreateDirectory(DirectoryPath);
21+
22+
[Benchmark]
23+
public void Testably_CreateDirectory()
24+
=> TestablyFileSystem.Directory.CreateDirectory(DirectoryPath);
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using BenchmarkDotNet.Attributes;
2+
using System.IO.Abstractions;
3+
using MockFileSystem = Testably.Abstractions.Testing.MockFileSystem;
4+
5+
namespace Testably.Abstractions.Benchmarks;
6+
7+
[RPlotExporter]
8+
[MemoryDiagnoser]
9+
public class CreateFileBenchmarks
10+
{
11+
private readonly string FileContent = "some file content";
12+
private readonly string FileName = "filename.txt";
13+
14+
private readonly IFileSystem SystemIOFileSystem =
15+
new System.IO.Abstractions.TestingHelpers.MockFileSystem();
16+
17+
private readonly IFileSystem TestablyFileSystem = new MockFileSystem();
18+
19+
[Benchmark]
20+
public void TestableIO_CreateDirectory()
21+
=> SystemIOFileSystem.File.WriteAllText(FileName, FileContent);
22+
23+
[Benchmark]
24+
public void Testably_CreateDirectory()
25+
=> TestablyFileSystem.File.WriteAllText(FileName, FileContent);
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using BenchmarkDotNet.Running;
2+
3+
namespace Testably.Abstractions.Benchmarks;
4+
5+
internal static class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<IsPackable>false</IsPackable>
4+
<IsTestable>false</IsTestable>
5+
<OutputType>Exe</OutputType>
6+
<GenerateProgramFile>false</GenerateProgramFile>
7+
<OutputPath>..\..\..\Build\Tests\$(MSBuildProjectName)</OutputPath>
8+
<TargetFrameworks>net8.0</TargetFrameworks>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" />
12+
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\..\Source\Testably.Abstractions.Testing\Testably.Abstractions.Testing.csproj" />
16+
</ItemGroup>
17+
</Project>

0 commit comments

Comments
 (0)