Merge pull request #539 from CJ-SPT/test-mod
Intoduce test mod and restructure test suites into their own solution folder
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\..\Build.props" />
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
|
||||
<PackageReference Include="FastCloner" Version="3.3.10" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Libraries\SPTarkov.Common\SPTarkov.Common.csproj" />
|
||||
<ProjectReference Include="..\..\Libraries\SPTarkov.DI\SPTarkov.DI.csproj" />
|
||||
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Assets\SPTarkov.Server.Assets.csproj" />
|
||||
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Core\SPTarkov.Server.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,50 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Benchmarks.Mock;
|
||||
using SPTarkov.Server.Core.Models.Spt.Templates;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
using SPTarkov.Server.Core.Utils.Cloners;
|
||||
using SPTarkov.Server.Core.Utils.Json;
|
||||
|
||||
namespace Benchmarks;
|
||||
|
||||
[SimpleJob(warmupCount: 10, iterationCount: 10)]
|
||||
[MemoryDiagnoser]
|
||||
public class ClonerBenchmarks
|
||||
{
|
||||
private ICloner _fastCloner;
|
||||
|
||||
private ICloner _jsonCloner;
|
||||
private ICloner _reflectionsCloner;
|
||||
private Templates? _templates;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
var jsonUtil = new JsonUtil([new SptJsonConverterRegistrator()]);
|
||||
var importer = new ImporterUtil(new MockLogger<ImporterUtil>(), new FileUtil(), jsonUtil);
|
||||
var loadTask = importer.LoadRecursiveAsync<Templates>("./Assets/database/templates/");
|
||||
loadTask.Wait();
|
||||
_templates = loadTask.Result;
|
||||
_jsonCloner = new JsonCloner(jsonUtil);
|
||||
_reflectionsCloner = new ReflectionsCloner(new MockLogger<ReflectionsCloner>());
|
||||
_fastCloner = new SPTarkov.Server.Core.Utils.Cloners.FastCloner();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void JsonCloner()
|
||||
{
|
||||
_jsonCloner.Clone(_templates);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void ReflectionsCloner()
|
||||
{
|
||||
_reflectionsCloner.Clone(_templates);
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void FastCloner()
|
||||
{
|
||||
_fastCloner.Clone(_templates);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
|
||||
namespace Benchmarks;
|
||||
|
||||
[SimpleJob(warmupCount: 10, iterationCount: 25)]
|
||||
[MemoryDiagnoser]
|
||||
public class MathUtilInterpBenchmarks
|
||||
{
|
||||
private MathUtil _mathUtil;
|
||||
|
||||
private double input = 15d;
|
||||
private List<double> x = [1, 10, 20, 30, 40, 50, 60];
|
||||
private List<double> y = [11000, 20000, 32000, 45000, 58000, 70000, 82000];
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_mathUtil = new MathUtil();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Interp()
|
||||
{
|
||||
_mathUtil.Interp1(input, x, y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using SPTarkov.Server.Core.Models.Logging;
|
||||
using SPTarkov.Server.Core.Models.Spt.Logging;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
|
||||
namespace Benchmarks.Mock;
|
||||
|
||||
public class MockLogger<T> : ISptLogger<T>
|
||||
{
|
||||
public void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null, Exception? ex = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Success(string data, Exception? ex = null)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Error(string data, Exception? ex = null)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Warning(string data, Exception? ex = null)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Info(string data, Exception? ex = null)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Debug(string data, Exception? ex = null)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Critical(string data, Exception? ex = null)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Log(
|
||||
LogLevel level,
|
||||
string data,
|
||||
LogTextColor? textColor = null,
|
||||
LogBackgroundColor? backgroundColor = null,
|
||||
Exception? ex = null
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void WriteToLogFile(string body, LogLevel level = LogLevel.Info)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsLogEnabled(LogLevel level)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void DumpAndStop()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void LogWithColor(string data, Exception? ex = null, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void WriteToLogFile(object body)
|
||||
{
|
||||
Console.WriteLine(body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using BenchmarkDotNet.Running;
|
||||
|
||||
namespace Benchmarks;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var summary = BenchmarkRunner.Run<ClonerBenchmarks>();
|
||||
Console.WriteLine(summary);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user