Basic benchmarking

This commit is contained in:
Simon Lübeß
2025-08-17 00:26:16 +02:00
parent fca126c960
commit 8f51d1c626
16 changed files with 665 additions and 26 deletions
+2 -3
View File
@@ -3,11 +3,10 @@ Dependencies = {corlib = "*", GlitchyEngine = "*", corlib = "*"}
[Project]
Name = "GlitchyEngine.Test"
TargetType = "BeefTest"
StartupObject = "GlitchyEngine.Test.Program"
StartupObject = "GlitchyEngine.Test.TestApp"
[Configs.Debug.Win64]
DebugWorkingDirectory = ""
DebugWorkingDirectory = "D:\\Development\\Projects\\Beef\\GlitchyEngine\\GlitchyEditor"
[Configs.Test.Win64]
DebugWorkingDirectory = "$(WorkspaceDir)\\GlitchyEditor"
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="singleClickDiffPreview" value="1" />
<option name="unhandledExceptionsIgnoreList" value="1" />
<option name="vcsConfiguration" value="3" />
</component>
</project>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
</project>
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoGeneratedRunConfigurationManager">
<projectFile profileName="Start Editor">../../../ScriptCore/ScriptCore.csproj</projectFile>
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="91b81792-3965-45fc-b023-6a7c118ee745" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"customColor": "",
"associatedIndex": 3
}]]></component>
<component name="ProjectId" id="31KeCm9hymLojzNB0dAwlIYVNgh" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "preferences.pluginManager",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RunManager">
<configuration name="ScriptCore: Start Editor" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/../../../ScriptCore/ScriptCore.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net9.0" />
<option name="LAUNCH_PROFILE_NAME" value="Start Editor" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="91b81792-3965-45fc-b023-6a7c118ee745" name="Changes" comment="" />
<created>1755277067318</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1755277067318</updated>
<workItem from="1755277069029" duration="595000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<breakpoint enabled="true" type="DotNet_Exception_Breakpoints">
<properties exception="System.OperationCanceledException" breakIfHandledByOtherCode="false" displayValue="System.OperationCanceledException" />
<option name="timeStamp" value="1" />
</breakpoint>
<breakpoint enabled="true" type="DotNet_Exception_Breakpoints">
<properties exception="System.Threading.Tasks.TaskCanceledException" breakIfHandledByOtherCode="false" displayValue="System.Threading.Tasks.TaskCanceledException" />
<option name="timeStamp" value="2" />
</breakpoint>
<breakpoint enabled="true" type="DotNet_Exception_Breakpoints">
<properties exception="System.Threading.ThreadAbortException" breakIfHandledByOtherCode="false" displayValue="System.Threading.ThreadAbortException" />
<option name="timeStamp" value="3" />
</breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
@@ -12,8 +12,8 @@ class ScriptEngineTestBase
{
public static void Setup()
{
Debug.WriteLine("Starting up ScriptEngine...");
Debug.WriteLine(Directory.GetCurrentDirectory(.. scope .()));
Console.WriteLine("Starting up ScriptEngine...");
Console.WriteLine(Directory.GetCurrentDirectory(.. scope .()));
ScriptEngine.Init();
ScriptEngine.SetAppAssemblyPath(@"..\GlitchyEngine.Test\content\TestProject\.cache\bin\TestProject.dll");
@@ -21,7 +21,7 @@ class ScriptEngineTestBase
protected static void Shutdown()
{
Debug.WriteLine("Shutting down ScriptEngine...");
Console.WriteLine("Shutting down ScriptEngine...");
ScriptEngine.Shutdown();
}
@@ -77,13 +77,15 @@ class ScriptEngineTestBase
time.Stop();
Debug.WriteLine($"Serialized in {time.ElapsedMicroseconds}μs ({time.ElapsedMilliseconds}ms)");
Console.WriteLine($"Serialized in {time.ElapsedMicroseconds}μs ({time.ElapsedMilliseconds}ms)");
scene.Stop();
Shutdown();
}
static String output = new .() ~ delete _;
class Benchmark
{
public Action BeforeAll;
@@ -103,25 +105,25 @@ class ScriptEngineTestBase
watch.Start();
for (int i < warmupRuns)
{
Debug.WriteLine($"Warmup run {i + 1}/{warmupRuns}...");
Console.WriteLine($"Warmup run {i + 1}/{warmupRuns}...");
TimeSpan duration = DoRun();
Debug.WriteLine($"Warmup run {i + 1} finished after {duration.TotalMilliseconds}ms.");
Console.WriteLine($"Warmup run {i + 1} finished after {duration.TotalMilliseconds}ms.");
}
watch.Stop();
Debug.WriteLine($"Warmup finished after {watch.Elapsed.TotalMilliseconds}ms");
Console.WriteLine($"Warmup finished after {watch.Elapsed.TotalMilliseconds}ms");
_runDurations = new TimeSpan[runs];
defer delete _runDurations;
for (int i < runs)
{
Debug.WriteLine($"Starting run {i + 1}/{runs}...");
Console.WriteLine($"Starting run {i + 1}/{runs}...");
watch.Restart();
_runDurations[i] = DoRun();
watch.Stop();
Debug.WriteLine($"Run {i + 1}: {_runDurations[i]} (total: {watch.Elapsed.TotalMilliseconds}ms).");
Console.WriteLine($"Run {i + 1}: {_runDurations[i]} (total: {watch.Elapsed.TotalMilliseconds}ms).");
}
TimeSpan totalRunTime = _runDurations.Sum();
@@ -130,10 +132,12 @@ class ScriptEngineTestBase
double varianceMs = _runDurations.Select(scope (d) => Math.Pow((d - meanRunTime).TotalMilliseconds, 2)).Sum() / runs;
TimeSpan stdDeviation = TimeSpan.FromMilliseconds(Math.Sqrt(varianceMs));
Debug.WriteLine($"Results:");
Debug.WriteLine($"Total Time ({runs} runs): {totalRunTime.TotalMilliseconds}ms");
Debug.WriteLine($"Average run Time: {meanRunTime.TotalMilliseconds}ms");
Debug.WriteLine($"Std deviation: {stdDeviation.TotalMilliseconds}ms");
Console.WriteLine($"Results:");
Console.WriteLine($"Total Time ({runs} runs): {totalRunTime.TotalMilliseconds}ms");
Console.WriteLine($"Average run Time: {meanRunTime.TotalMilliseconds}ms");
Console.WriteLine($"Std deviation: {stdDeviation.TotalMilliseconds}ms");
output.AppendF($"Total: {totalRunTime.TotalMilliseconds}ms | Mean: {meanRunTime.TotalMilliseconds}ms Std: {stdDeviation.TotalMilliseconds}ms\n");
AfterAll?.Invoke();
}
@@ -162,7 +166,6 @@ class ScriptEngineTestBase
Scene scene = new Scene();
defer scene.ReleaseRef();
ScriptInstanceSerializer serializer = null;
let benchmark = scope Benchmark();
@@ -182,7 +185,8 @@ class ScriptEngineTestBase
scene.Stop();
};
Debug.WriteLine("Benchmark empty scene:");
Console.WriteLine("Benchmark empty scene:");
output.AppendF("Benchmark empty scene:");
{
benchmark.Run();
}
@@ -192,7 +196,8 @@ class ScriptEngineTestBase
void BenchmarkTrivialEntity(int entityCount)
{
Debug.WriteLine($"Benchmark {entityCount} Trivial Entity:");
Console.WriteLine($"Benchmark {entityCount} Trivial Entity:");
output.AppendF($"Benchmark {entityCount} Trivial Entity:");
for (int i < entityCount)
{
@@ -220,7 +225,8 @@ class ScriptEngineTestBase
void BenchmarkLargeEntity(int entityCount)
{
Debug.WriteLine($"Benchmark {entityCount} Large Entity:");
Console.WriteLine($"Benchmark {entityCount} Large Entity:");
output.AppendF($"Benchmark {entityCount} Large Entity:");
for (int i < entityCount)
{
@@ -248,5 +254,7 @@ class ScriptEngineTestBase
// After Bench
Shutdown();
File.WriteAllText("test.log", output);
}
}
+7 -1
View File
@@ -1,9 +1,15 @@
using System;
using GlitchyEngine.Test.Base;
namespace GlitchyEngine.Test;
class TestApp
{
/// Provide a stup implementation for CreateApplication, so that the linker is happy.
public static void Main(String[] args)
{
ScriptEngineTestBase.BenchmarkSerializer();
}
/// Provide a stub implementation for CreateApplication, so that the linker is happy.
[Export, LinkName("CreateApplication")]
public static Application CreateApplication(String[] args)
{