Masstesting new var: Threadcount

corrected capitalization
This commit is contained in:
glax 2023-04-21 14:29:52 +02:00
parent aa8b1e4451
commit cf5b1e9945

View File

@ -26,7 +26,7 @@ public class Server
Coordinates start = new (48.7933798f, 9.8275859f);
Coordinates finish = new (48.795918f, 9.021618f);
TestVariables(workingDir, start, finish);
TestVariables(workingDir, start, finish, 4);
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
@ -66,11 +66,11 @@ public class Server
#pragma warning restore CA1416*/
}
private static void TestVariables(string workingDir, Coordinates start, Coordinates finish)
private static void TestVariables(string workingDir, Coordinates start, Coordinates finish, int threads)
{
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
Queue<Thread> CalcThreads = new();
Queue<Thread> calcThreads = new();
for (double sameRoadPriority = 0.002; sameRoadPriority < 0.4; sameRoadPriority += 0.02)
{
@ -81,7 +81,7 @@ public class Server
double priority = roadLevelPriority;
double roadPriority = sameRoadPriority;
double factor = angleWeightFactor;
CalcThreads.Enqueue(new Thread(() =>
calcThreads.Enqueue(new Thread(() =>
{
Pathfinder testresult = new Pathfinder(workingDir).AStar(start,
finish, Tag.SpeedType.car, priority, roadPriority,
@ -94,24 +94,27 @@ public class Server
}
}
int totalTasks = CalcThreads.Count;
int completed = 0;
int totalTasks = calcThreads.Count;
int completedTasks = 0;
DateTime startTime = DateTime.Now;
HashSet<Thread> runningThreads = new();
while (CalcThreads.Count > 0)
while (calcThreads.Count > 0)
{
while (runningThreads.Count < 16 && CalcThreads.Count > 0)
while (runningThreads.Count < threads && calcThreads.Count > 0)
{
Thread t = CalcThreads.Dequeue();
Thread t = calcThreads.Dequeue();
runningThreads.Add(t);
t.Start();
}
int newCompleted = runningThreads.RemoveWhere(thread => !thread.IsAlive);
completed += newCompleted;
if(newCompleted > 0)
Console.WriteLine($"To calculate: {CalcThreads.Count}/{totalTasks} Average Time: {(DateTime.Now - startTime)/(completed)} Elapsed: {DateTime.Now - startTime} Remaining: {(DateTime.Now - startTime)/(completed)*CalcThreads.Count}");
int newCompletedTasks = runningThreads.RemoveWhere(thread => !thread.IsAlive);
completedTasks += newCompletedTasks;
if (newCompletedTasks > 0)
{
TimeSpan elapsedTime = DateTime.Now - startTime;
Console.WriteLine($"To calculate: {calcThreads.Count}/{totalTasks} Time Average: {(elapsedTime)/(completedTasks)} Elapsed: {elapsedTime} Remaining: {(elapsedTime)/(completedTasks)*calcThreads.Count}");
}
}
}
}