Skip to content

Commit

Permalink
Code cleanup and fix configuration error (#25)
Browse files Browse the repository at this point in the history
* Benchmarks and more unit tests, plus resulting bug fixes

* change benchmarks

* error suppression was not needed anymore

* improve benchmarks

* fix Visual Studio configuration error

* code cleanup

* prevent benchmark to be auto-optimized
  • Loading branch information
JonathanBout authored Dec 5, 2024
1 parent 2d3c961 commit 7008bc6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 50 deletions.
15 changes: 7 additions & 8 deletions SimpleCDN.Benchmarks/Benchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleCDN.Benchmarks
{
[MemoryDiagnoser(false)]
//[SimpleJob(RuntimeMoniker.NativeAot90)]
[SimpleJob(RuntimeMoniker.Net90)]
[MemoryDiagnoser(false)]
public class Benchmarks
{
public static IEnumerable<char[]> Paths =>
Expand All @@ -25,14 +19,19 @@ public class Benchmarks

[Benchmark(OperationsPerInvoke = NormalizationBenchmarkIterationsPerInvoke)]
[ArgumentsSource(nameof(Paths))]
public void Normalize(char[] path)
public long Normalize(char[] path)
{
long res = 0;

for (var i = 0; i < NormalizationBenchmarkIterationsPerInvoke; i++)
{
var copy = path.ToArray();
var span = copy.AsSpan();
Helpers.Extensions.Normalize(ref span);
res += span.BinarySearch('/');
}

return res;
}
}
}
4 changes: 1 addition & 3 deletions SimpleCDN.Tests.Integration/EndpointTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Mvc.Testing;

namespace SimpleCDN.Tests.Integration
namespace SimpleCDN.Tests.Integration
{
public class EndpointTests : IClassFixture<CustomWebApplicationFactory>
{
Expand Down
4 changes: 0 additions & 4 deletions SimpleCDN.Tests/CacheManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using SimpleCDN.Cache;
using SimpleCDN.Services;
using SimpleCDN.Tests.Mocks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleCDN.Tests
{
Expand Down
5 changes: 0 additions & 5 deletions SimpleCDN.Tests/Mocks/DistributedCacheMock.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Microsoft.Extensions.Caching.Distributed;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleCDN.Tests.Mocks
{
Expand Down
8 changes: 1 addition & 7 deletions SimpleCDN.Tests/NormalizeTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleCDN.Tests
namespace SimpleCDN.Tests
{
[TestFixture]
public class NormalizeTests
Expand Down
44 changes: 21 additions & 23 deletions SimpleCDN.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,44 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35507.96
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCDN", "SimpleCDN\SimpleCDN.csproj", "{E15F4BC2-E820-48D6-857B-E2DC9E35D370}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCDN.Tests", "SimpleCDN.Tests\SimpleCDN.Tests.csproj", "{6D8833B9-7EC8-4212-83DD-ABCCD677309E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCDN", "SimpleCDN\SimpleCDN.csproj", "{9C7F11BA-ECF0-8CD1-D1F5-DB31D692724E}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{81DDED9D-158B-E303-5F62-77A2896D2A5A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCDN.Tests.Integration", "SimpleCDN.Tests.Integration\SimpleCDN.Tests.Integration.csproj", "{F79E71E8-89D8-46F7-802C-CFDF3A77447D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCDN.Tests", "SimpleCDN.Tests\SimpleCDN.Tests.csproj", "{9F41AC4B-73A5-AED7-2FAD-13532040B2E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCDN.Benchmarks", "SimpleCDN.Benchmarks\SimpleCDN.Benchmarks.csproj", "{01B35836-CD1D-0631-A280-04996E3E2058}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCDN.Benchmarks", "SimpleCDN.Benchmarks\SimpleCDN.Benchmarks.csproj", "{73BC9966-46FF-40D8-89F4-C990B15370A2}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCDN.Tests.Integration", "SimpleCDN.Tests.Integration\SimpleCDN.Tests.Integration.csproj", "{748DF05A-61E9-3214-6751-2FB8D9C75A1C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E15F4BC2-E820-48D6-857B-E2DC9E35D370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E15F4BC2-E820-48D6-857B-E2DC9E35D370}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E15F4BC2-E820-48D6-857B-E2DC9E35D370}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E15F4BC2-E820-48D6-857B-E2DC9E35D370}.Release|Any CPU.Build.0 = Release|Any CPU
{6D8833B9-7EC8-4212-83DD-ABCCD677309E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D8833B9-7EC8-4212-83DD-ABCCD677309E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D8833B9-7EC8-4212-83DD-ABCCD677309E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D8833B9-7EC8-4212-83DD-ABCCD677309E}.Release|Any CPU.Build.0 = Release|Any CPU
{9C7F11BA-ECF0-8CD1-D1F5-DB31D692724E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C7F11BA-ECF0-8CD1-D1F5-DB31D692724E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C7F11BA-ECF0-8CD1-D1F5-DB31D692724E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C7F11BA-ECF0-8CD1-D1F5-DB31D692724E}.Release|Any CPU.Build.0 = Release|Any CPU
{81DDED9D-158B-E303-5F62-77A2896D2A5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81DDED9D-158B-E303-5F62-77A2896D2A5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81DDED9D-158B-E303-5F62-77A2896D2A5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81DDED9D-158B-E303-5F62-77A2896D2A5A}.Release|Any CPU.Build.0 = Release|Any CPU
{F79E71E8-89D8-46F7-802C-CFDF3A77447D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F79E71E8-89D8-46F7-802C-CFDF3A77447D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F79E71E8-89D8-46F7-802C-CFDF3A77447D}.Release|Any CPU.Build.0 = Release|Any CPU
{73BC9966-46FF-40D8-89F4-C990B15370A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73BC9966-46FF-40D8-89F4-C990B15370A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73BC9966-46FF-40D8-89F4-C990B15370A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73BC9966-46FF-40D8-89F4-C990B15370A2}.Release|Any CPU.Build.0 = Release|Any CPU
{9F41AC4B-73A5-AED7-2FAD-13532040B2E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F41AC4B-73A5-AED7-2FAD-13532040B2E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F41AC4B-73A5-AED7-2FAD-13532040B2E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F41AC4B-73A5-AED7-2FAD-13532040B2E1}.Release|Any CPU.Build.0 = Release|Any CPU
{01B35836-CD1D-0631-A280-04996E3E2058}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01B35836-CD1D-0631-A280-04996E3E2058}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01B35836-CD1D-0631-A280-04996E3E2058}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01B35836-CD1D-0631-A280-04996E3E2058}.Release|Any CPU.Build.0 = Release|Any CPU
{748DF05A-61E9-3214-6751-2FB8D9C75A1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{748DF05A-61E9-3214-6751-2FB8D9C75A1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{748DF05A-61E9-3214-6751-2FB8D9C75A1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{748DF05A-61E9-3214-6751-2FB8D9C75A1C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D252A113-93EA-49FE-9080-E3A41CD60F25}
EndGlobalSection
EndGlobal

0 comments on commit 7008bc6

Please sign in to comment.