From cf5b1e9945198c1eec12b6467240e2aa7939ada6 Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 21 Apr 2023 14:29:52 +0200 Subject: [PATCH] Masstesting new var: Threadcount corrected capitalization --- Server/Server.cs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Server/Server.cs b/Server/Server.cs index dab519d..51ca258 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -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 CalcThreads = new(); + Queue 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 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}"); + } } } } \ No newline at end of file