Add benchmarking and trace build config

This commit is contained in:
Asriel Camora
2023-11-04 13:49:47 -07:00
parent d08fedb247
commit 4f953f2fa3
12 changed files with 158 additions and 48 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
.vs/ .vs/
obj/ obj/
bin/ bin/
*.user *.user
BenchmarkDotNet.Artifacts/
+97
View File
@@ -0,0 +1,97 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using Craftimizer.Simulator;
using Craftimizer.Solver;
namespace Craftimizer.Benchmark;
[SimpleJob(RunStrategy.Monitoring)]
[MinColumn, Q1Column, Q3Column, MaxColumn]
public class Bench
{
private static SimulationInput[] Inputs { get; } = new SimulationInput[] {
// https://craftingway.app/rotation/loud-namazu-jVe9Y
// Chondrite Saw
new(new()
{
Craftsmanship = 3304,
Control = 3374,
CP = 575,
Level = 90,
CanUseManipulation = true,
HasSplendorousBuff = false,
IsSpecialist = false,
CLvl = 560,
},
new()
{
IsExpert = false,
ClassJobLevel = 90,
RLvl = 560,
ConditionsFlag = 0b1111,
MaxDurability = 80,
MaxQuality = 7200,
MaxProgress = 3500,
QualityModifier = 80,
QualityDivider = 115,
ProgressModifier = 90,
ProgressDivider = 130
}),
// https://craftingway.app/rotation/sandy-fafnir-doVCs
// Classical Longsword
new(new()
{
Craftsmanship = 3290,
Control = 3541,
CP = 649,
Level = 90,
CanUseManipulation = true,
HasSplendorousBuff = false,
IsSpecialist = false,
CLvl = 560,
},
new()
{
IsExpert = false,
ClassJobLevel = 90,
RLvl = 580,
ConditionsFlag = 0b1111,
MaxDurability = 70,
MaxQuality = 10920,
MaxProgress = 3900,
QualityModifier = 70,
QualityDivider = 115,
ProgressModifier = 80,
ProgressDivider = 130
})
};
public static IEnumerable<SimulationState> States => Inputs.Select(i => new SimulationState(i));
public static IEnumerable<SolverConfig> Configs => new SolverConfig[]
{
new()
{
Iterations = 100_000,
ForkCount = 32,
FurcatedActionCount = 16,
MaxStepCount = 30,
}
};
[ParamsSource(nameof(States))]
public SimulationState State { get; set; }
[ParamsSource(nameof(Configs))]
public SolverConfig Config { get; set; }
[Benchmark]
public async Task<float> Solve()
{
var solver = new Solver.Solver(Config, State);
solver.Start();
var (_, s) = await solver.GetTask().ConfigureAwait(false);
return (float)s.Quality / s.Input.Recipe.MaxQuality;
}
}
+2
View File
@@ -5,6 +5,8 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Platforms>x64</Platforms>
<Configurations>Debug;Release;Trace</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
+6 -4
View File
@@ -1,3 +1,4 @@
using BenchmarkDotNet.Running;
using Craftimizer.Simulator; using Craftimizer.Simulator;
using Craftimizer.Simulator.Actions; using Craftimizer.Simulator.Actions;
using Craftimizer.Solver; using Craftimizer.Solver;
@@ -7,10 +8,11 @@ namespace Craftimizer.Benchmark;
internal static class Program internal static class Program
{ {
private static async Task Main() private static async Task Main(string[] args)
{ {
//var summary = BenchmarkRunner.Run<Bench>(); Environment.SetEnvironmentVariable("IS_BENCH", "1");
//return; BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
return;
//TypeLayout.PrintLayout<ArenaNode<SimulationNode>>(true); //TypeLayout.PrintLayout<ArenaNode<SimulationNode>>(true);
//return; //return;
@@ -78,7 +80,7 @@ internal static class Program
Console.WriteLine($"{state.Quality} {state.CP} {state.Progress} {state.Durability}"); Console.WriteLine($"{state.Quality} {state.CP} {state.Progress} {state.Durability}");
//return; //return;
var solver = new Solver.Solver(config, state); var solver = new Solver.Solver(config, state);
solver.OnLog += s => Console.WriteLine(s); solver.OnLog += Console.WriteLine;
solver.OnNewAction += s => Console.WriteLine(s); solver.OnNewAction += s => Console.WriteLine(s);
solver.Start(); solver.Start();
var (_, s) = await solver.GetTask().ConfigureAwait(false); var (_, s) = await solver.GetTask().ConfigureAwait(false);
+6
View File
@@ -7,6 +7,8 @@
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject> <IsTestProject>true</IsTestProject>
<Platforms>x64</Platforms>
<Configurations>Debug;Release</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -21,4 +23,8 @@
<ProjectReference Include="..\Solver\Craftimizer.Solver.csproj" /> <ProjectReference Include="..\Solver\Craftimizer.Solver.csproj" />
</ItemGroup> </ItemGroup>
<PropertyGroup>
<DefineConstants Condition="'$(IS_BENCH)'=='1'">$(DefineConstants);IS_DETERMINISTIC</DefineConstants>
</PropertyGroup>
</Project> </Project>
-2
View File
@@ -1,6 +1,4 @@
using Craftimizer.Simulator.Actions; using Craftimizer.Simulator.Actions;
using System;
using System.Reflection;
namespace Craftimizer.Test.Simulator; namespace Craftimizer.Test.Simulator;
+4
View File
@@ -105,6 +105,10 @@ public class ActionSetTests
[TestMethod] [TestMethod]
public void TestRandomIndex() public void TestRandomIndex()
{ {
#if IS_DETERMINISTIC
Assert.Inconclusive("Craftimizer is built for benchmarking; all random actions are deterministic and not actually random.");
#endif
var actions = new[] var actions = new[]
{ {
ActionType.BasicTouch, ActionType.BasicTouch,
+26 -39
View File
@@ -17,56 +17,43 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Craftimizer.Solver", "Solve
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3} = {172EE849-AC7E-4F2A-ACAB-EF9D065523B3} {172EE849-AC7E-4F2A-ACAB-EF9D065523B3} = {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Craftimizer.Test", "Craftimizer.Test\Craftimizer.Test.csproj", "{C3AEA981-9DA8-405C-995B-86528493891B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Craftimizer.Test", "Craftimizer.Test\Craftimizer.Test.csproj", "{C3AEA981-9DA8-405C-995B-86528493891B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64 Release|x64 = Release|x64
Trace|x64 = Trace|x64
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|Any CPU.ActiveCfg = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|Any CPU.Build.0 = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.ActiveCfg = Debug|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.ActiveCfg = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.Build.0 = Debug|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.Build.0 = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|Any CPU.ActiveCfg = Release|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|Any CPU.Build.0 = Release|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.ActiveCfg = Release|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.ActiveCfg = Release|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.Build.0 = Release|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.Build.0 = Release|x64
{057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {13C812E9-0D42-4B95-8646-40EEBF30636F}.Trace|x64.ActiveCfg = Release|x64
{057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|Any CPU.Build.0 = Debug|Any CPU {057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|x64.ActiveCfg = Debug|x64
{057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|x64.ActiveCfg = Debug|Any CPU {057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|x64.Build.0 = Debug|x64
{057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|x64.Build.0 = Debug|Any CPU {057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|x64.ActiveCfg = Release|x64
{057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|Any CPU.ActiveCfg = Release|Any CPU {057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|x64.Build.0 = Release|x64
{057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|Any CPU.Build.0 = Release|Any CPU {057C4B64-4D99-4847-9BCF-966571CAE57C}.Trace|x64.ActiveCfg = Trace|x64
{057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|x64.ActiveCfg = Release|Any CPU {057C4B64-4D99-4847-9BCF-966571CAE57C}.Trace|x64.Build.0 = Trace|x64
{057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|x64.Build.0 = Release|Any CPU {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|x64.ActiveCfg = Debug|x64
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|x64.Build.0 = Debug|x64
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|Any CPU.Build.0 = Debug|Any CPU {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|x64.ActiveCfg = Release|x64
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|x64.ActiveCfg = Debug|Any CPU {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|x64.Build.0 = Release|x64
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|x64.Build.0 = Debug|Any CPU {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Trace|x64.ActiveCfg = Trace|x64
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|Any CPU.ActiveCfg = Release|Any CPU {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Trace|x64.Build.0 = Trace|x64
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|Any CPU.Build.0 = Release|Any CPU {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|x64.ActiveCfg = Debug|x64
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|x64.ActiveCfg = Release|Any CPU {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|x64.Build.0 = Debug|x64
{172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|x64.Build.0 = Release|Any CPU {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|x64.ActiveCfg = Release|x64
{2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|x64.Build.0 = Release|x64
{2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|Any CPU.Build.0 = Debug|Any CPU {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Trace|x64.ActiveCfg = Trace|x64
{2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|x64.ActiveCfg = Debug|Any CPU {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Trace|x64.Build.0 = Trace|x64
{2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|x64.Build.0 = Debug|Any CPU {C3AEA981-9DA8-405C-995B-86528493891B}.Debug|x64.ActiveCfg = Debug|x64
{2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|Any CPU.ActiveCfg = Release|Any CPU {C3AEA981-9DA8-405C-995B-86528493891B}.Debug|x64.Build.0 = Debug|x64
{2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|Any CPU.Build.0 = Release|Any CPU {C3AEA981-9DA8-405C-995B-86528493891B}.Release|x64.ActiveCfg = Release|x64
{2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|x64.ActiveCfg = Release|Any CPU {C3AEA981-9DA8-405C-995B-86528493891B}.Release|x64.Build.0 = Release|x64
{2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|x64.Build.0 = Release|Any CPU {C3AEA981-9DA8-405C-995B-86528493891B}.Trace|x64.ActiveCfg = Release|x64
{C3AEA981-9DA8-405C-995B-86528493891B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3AEA981-9DA8-405C-995B-86528493891B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3AEA981-9DA8-405C-995B-86528493891B}.Debug|x64.ActiveCfg = Debug|Any CPU
{C3AEA981-9DA8-405C-995B-86528493891B}.Debug|x64.Build.0 = Debug|Any CPU
{C3AEA981-9DA8-405C-995B-86528493891B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3AEA981-9DA8-405C-995B-86528493891B}.Release|Any CPU.Build.0 = Release|Any CPU
{C3AEA981-9DA8-405C-995B-86528493891B}.Release|x64.ActiveCfg = Release|Any CPU
{C3AEA981-9DA8-405C-995B-86528493891B}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
+1
View File
@@ -4,6 +4,7 @@
<Authors>Asriel Camora</Authors> <Authors>Asriel Camora</Authors>
<Version>1.9.1.0</Version> <Version>1.9.1.0</Version>
<PackageProjectUrl>https://github.com/WorkingRobot/craftimizer.git</PackageProjectUrl> <PackageProjectUrl>https://github.com/WorkingRobot/craftimizer.git</PackageProjectUrl>
<Configurations>Debug;Release</Configurations>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
+7
View File
@@ -4,6 +4,8 @@
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Platforms>x64</Platforms>
<Configurations>Debug;Release;Trace</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -13,4 +15,9 @@
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<PropertyGroup>
<DefineConstants Condition="'$(IS_BENCH)'=='1'">$(DefineConstants);IS_DETERMINISTIC</DefineConstants>
<DefineConstants Condition="'$(Configuration)' == 'Trace'">$(DefineConstants);IS_DETERMINISTIC;IS_TRACE</DefineConstants>
</PropertyGroup>
</Project> </Project>
-2
View File
@@ -5,8 +5,6 @@ using System.Runtime.CompilerServices;
namespace Craftimizer.Solver; namespace Craftimizer.Solver;
// #define IS_DETERMINISTIC
public struct ActionSet public struct ActionSet
{ {
private uint bits; private uint bits;
+7
View File
@@ -5,6 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Platforms>x64</Platforms>
<Configurations>Debug;Release;Trace</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -18,4 +20,9 @@
<ProjectReference Include="..\Simulator\Craftimizer.Simulator.csproj" /> <ProjectReference Include="..\Simulator\Craftimizer.Simulator.csproj" />
</ItemGroup> </ItemGroup>
<PropertyGroup>
<DefineConstants Condition="'$(IS_BENCH)'=='1'">$(DefineConstants);IS_DETERMINISTIC</DefineConstants>
<DefineConstants Condition="'$(Configuration)' == 'Trace'">$(DefineConstants);IS_DETERMINISTIC;IS_TRACE</DefineConstants>
</PropertyGroup>
</Project> </Project>