Implement scheduling system with parallel execution support and dummy job systems
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user