Implement scheduling system with parallel execution support and dummy job systems

This commit is contained in:
max
2026-08-07 12:14:02 +02:00
parent a0f2713fdc
commit 0132c1326d
14 changed files with 844 additions and 5 deletions
@@ -0,0 +1,54 @@
using System.Diagnostics;
namespace Nerfed.Runtime.Systems.Synthetic;
internal static class DummyWorkloadRunner
{
public static int Run(TimeSpan duration, DummyWorkloadMode mode, int seed)
{
return mode switch
{
DummyWorkloadMode.Sleep => Sleep(duration, seed),
DummyWorkloadMode.Compute => Compute(duration, seed),
_ => Spin(duration, seed),
};
}
private static int Sleep(TimeSpan duration, int seed)
{
if (duration > TimeSpan.Zero)
{
Thread.Sleep(duration);
}
return seed;
}
private static int Spin(TimeSpan duration, int seed)
{
Stopwatch stopwatch = Stopwatch.StartNew();
int value = seed;
while (stopwatch.Elapsed < duration)
{
value = unchecked((value * 1664525) + 1013904223);
Thread.SpinWait(128);
}
return value;
}
private static int Compute(TimeSpan duration, int seed)
{
Stopwatch stopwatch = Stopwatch.StartNew();
int value = seed;
while (stopwatch.Elapsed < duration)
{
for (int i = 0; i < 2048; i++)
{
value = unchecked((value << 5) - value + i);
}
}
return value;
}
}