Performance Fish
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<EnableNETAnalyzers>True</EnableNETAnalyzers>
|
||||
<AnalysisLevel>preview-all</AnalysisLevel>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<Configurations>v1.3;v1.4</Configurations>
|
||||
</PropertyGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(Configuration)' == 'v1.3'">
|
||||
<ItemGroup>
|
||||
<!--PackageReference Include="Krafs.Rimworld.Ref" Version="1.3.*" /-->
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>E:\RimWorld\1.3\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>E:\RimWorld\1.3\RimWorldWin64_Data\Managed\mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>E:\RimWorld\1.3\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.IMGUIModule">
|
||||
<HintPath>E:\RimWorld\1.3\RimWorldWin64_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="1Fishery">
|
||||
<HintPath>..\..\..\Fishery\1.3\Assemblies\1Fishery.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PerformanceFish">
|
||||
<HintPath>..\..\1.3\Assemblies\PerformanceFish.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="'$(Configuration)' == 'v1.4'">
|
||||
<ItemGroup>
|
||||
<!--PackageReference Include="Krafs.Rimworld.Ref" Version="1.4.*-*" /-->
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>E:\RimWorld\1.4\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>E:\RimWorld\1.4\RimWorldWin64_Data\Managed\mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>E:\RimWorld\1.4\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.IMGUIModule">
|
||||
<HintPath>E:\RimWorld\1.4\RimWorldWin64_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="1Fishery">
|
||||
<HintPath>..\..\..\Fishery\1.4\Assemblies\1Fishery.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PerformanceFish">
|
||||
<HintPath>..\..\1.4\Assemblies\PerformanceFish.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Lib.Harmony" Version="2.*" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
|
||||
<PackageReference Include="xunit" Version="2.*" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.*">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.*">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32728.150
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerformanceFish.Tests", "PerformanceFish.Tests.csproj", "{D3852300-E6CA-4561-849F-B9F827703B3A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
v1.3|Any CPU = v1.3|Any CPU
|
||||
v1.4|Any CPU = v1.4|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D3852300-E6CA-4561-849F-B9F827703B3A}.v1.3|Any CPU.ActiveCfg = v1.3|Any CPU
|
||||
{D3852300-E6CA-4561-849F-B9F827703B3A}.v1.3|Any CPU.Build.0 = v1.3|Any CPU
|
||||
{D3852300-E6CA-4561-849F-B9F827703B3A}.v1.4|Any CPU.ActiveCfg = v1.4|Any CPU
|
||||
{D3852300-E6CA-4561-849F-B9F827703B3A}.v1.4|Any CPU.Build.0 = v1.4|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {9E98D95E-68FE-465E-A330-11540608ADAD}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,101 @@
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using Xunit;
|
||||
global using Xunit.Abstractions;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace PerformanceFish.Tests;
|
||||
|
||||
public class ReflectionCaching
|
||||
{
|
||||
internal static void InitializeLog(ITestOutputHelper output)
|
||||
{
|
||||
Log.Config.Message = output.WriteLine;
|
||||
Log.Config.Warning = output.WriteLine;
|
||||
Log.Config.Error = message => throw new(message);
|
||||
}
|
||||
|
||||
public class GetValue
|
||||
{
|
||||
public GetValue(ITestOutputHelper output) => InitializeLog(output);
|
||||
|
||||
private const int COUNT = 500;
|
||||
|
||||
public static IEnumerable<object[]> Data
|
||||
=> new object[][]
|
||||
{
|
||||
new[] { nameof(_enum) },
|
||||
new[] { nameof(_nullableWithoutValue) },
|
||||
new[] { nameof(_nullableWithValue) },
|
||||
new[] { nameof(_primitive) },
|
||||
new[] { nameof(_reference) },
|
||||
new[] { nameof(CONST) }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Data))]
|
||||
public void Test(string name)
|
||||
{
|
||||
if (name == nameof(CONST))
|
||||
{
|
||||
Log.Message("sPeCiFiEd MeThOd Is NoT sUpPoRtEd!\nworks fine on mono however");
|
||||
return;
|
||||
}
|
||||
|
||||
var field = _type.GetField(name, AccessTools.all);
|
||||
Assert.NotNull(field);
|
||||
|
||||
object result = null;
|
||||
|
||||
for (var i = 0; i < COUNT; i++)
|
||||
System.ReflectionCaching.FieldInfoPatches.GetValue_Patch.Prefix(field, null, ref result);
|
||||
|
||||
Assert.Equal(result, field.GetValue(null));
|
||||
}
|
||||
|
||||
private static TypeCode _enum = TypeCode.Int32;
|
||||
private static int? _nullableWithoutValue = null;
|
||||
private static int? _nullableWithValue = 1;
|
||||
private static int _primitive = 0;
|
||||
private static object _reference = new();
|
||||
private const string CONST = "a";
|
||||
private static Type _type = typeof(GetValue);
|
||||
}
|
||||
|
||||
public class SetValue
|
||||
{
|
||||
public SetValue(ITestOutputHelper output) => InitializeLog(output);
|
||||
|
||||
private const int COUNT = 500;
|
||||
|
||||
public static IEnumerable<object[]> Data
|
||||
=> new object[][]
|
||||
{
|
||||
new object[] { nameof(_enum), TypeCode.Byte },
|
||||
new object[] { nameof(_nullableWithoutValue), 1 },
|
||||
new object[] { nameof(_nullableWithValue), null },
|
||||
new object[] { nameof(_primitive), 1 },
|
||||
new object[] { nameof(_reference), new() }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Data))]
|
||||
public void Test(string name, object input)
|
||||
{
|
||||
var field = _type.GetField(name, AccessTools.all);
|
||||
Assert.NotNull(field);
|
||||
|
||||
for (var i = 0; i < COUNT; i++)
|
||||
System.ReflectionCaching.FieldInfoPatches.SetValue_Patch.Prefix(field, null, input);
|
||||
|
||||
Assert.Equal(input, field.GetValue(null));
|
||||
}
|
||||
|
||||
private static TypeCode _enum = TypeCode.Int32;
|
||||
private static int? _nullableWithoutValue = null;
|
||||
private static int? _nullableWithValue = 1;
|
||||
private static int _primitive = 0;
|
||||
private static object _reference = new();
|
||||
private static Type _type = typeof(SetValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user