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