Add Benchmark option
This commit is contained in:
parent
e6e0bc17ce
commit
7bf94fa2fd
28
Graph_Renderer/Benchmark.cs
Normal file
28
Graph_Renderer/Benchmark.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using astar;
|
||||
using astar.PathingHelper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Graph_Renderer;
|
||||
|
||||
public static class Benchmark
|
||||
{
|
||||
public static void Run(float startLat, float startLon, float endLat, float endLon, float regionSize, string importPath, string exportPath, ILogger? logger = null)
|
||||
{
|
||||
for (int explorationDistance = 1000; explorationDistance <= 1400; explorationDistance += 100)
|
||||
{
|
||||
for (int additionalExploration = 45; additionalExploration <= 80; additionalExploration += 5)
|
||||
{
|
||||
logger?.LogInformation($"Speed:{0:0.00} Angle:{0.07f:0.00} DistanceImproved:{0:0.00} DistanceSpeed:{0:0.00} ExplorationDistance:{explorationDistance:000} Additional:{additionalExploration:000}");
|
||||
string name = $"{0:0.00}${0.07f:0.00}${0:0.00}${0:0.00}${explorationDistance:000}${additionalExploration:000}";
|
||||
DateTime start = DateTime.Now;
|
||||
Route r = new Astar(new(0, 0.07f, 0, 0),explorationDistance).
|
||||
FindPath(startLat, startLon, endLat, endLon, regionSize, true, PathMeasure.Time, additionalExploration, importPath, logger);
|
||||
DateTime end = DateTime.Now;
|
||||
Directory.CreateDirectory(Path.Join(exportPath, "benchmark", name));
|
||||
File.WriteAllText(Path.Join(exportPath, "benchmark", name, "stats.txt"), $"{end - start:hh\\:mm\\:ss\\.fff}\n{r}");
|
||||
logger?.LogInformation($"Took {end-start:hh\\:mm\\:ss\\.fff}");
|
||||
Renderer.Render(r, 20000, Path.Join(exportPath, "benchmark", name, "render.png"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -18,14 +18,17 @@ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
Argument regionArg = new (["-r", "--regionSize"], 1, "Region-Size");
|
||||
Argument importPathArg = new (["-i", "--importPath"], 1, "Region-Directory");
|
||||
Argument routeCoordinateArg = new(["-c", "--route", "--coordinates"], 4, "Start and end coordinates");
|
||||
Argument exportRenderPathArg = new(["-e", "--exportPath"], 1, "Export file path.");
|
||||
Argument benchmarkArg = new(["-b", "--benchmark"], 0, "Run tests");
|
||||
|
||||
ArgumentFetcher af = new ([regionArg, importPathArg, routeCoordinateArg]);
|
||||
ArgumentFetcher af = new ([regionArg, importPathArg, routeCoordinateArg, exportRenderPathArg, benchmarkArg]);
|
||||
|
||||
Dictionary<Argument, string[]> arguments = af.Fetch(args);
|
||||
|
||||
if (!arguments.TryGetValue(regionArg, out string[]? regionVal) ||
|
||||
!float.TryParse(regionVal[0], NumberFormatInfo.InvariantInfo, out float regionSize) ||
|
||||
!arguments.TryGetValue(importPathArg, out string[]? importPathVal) ||
|
||||
!arguments.TryGetValue(exportRenderPathArg, out string[]? exportRenderPath) ||
|
||||
!arguments.TryGetValue(routeCoordinateArg, out string[]? routeCoordinateVal) ||
|
||||
!float.TryParse(routeCoordinateVal[0], NumberFormatInfo.InvariantInfo, out float startLat) ||
|
||||
!float.TryParse(routeCoordinateVal[1], NumberFormatInfo.InvariantInfo, out float startLon) ||
|
||||
@ -37,8 +40,14 @@ if (!arguments.TryGetValue(regionArg, out string[]? regionVal) ||
|
||||
|
||||
Logger logger = new(LogLevel.Information, consoleOut: Console.Out);
|
||||
|
||||
Route r = Astar.FindPath(startLat, startLon, endLat, endLon, regionSize, true, PathMeasure.Time, importPathVal[0], logger);
|
||||
if (!arguments.ContainsKey(benchmarkArg))
|
||||
{
|
||||
Route r = new Astar().FindPath(startLat, startLon, endLat, endLon, regionSize, true, PathMeasure.Time, 300, importPathVal[0], logger);
|
||||
Renderer.Render(r, 20000, exportRenderPath[0]);
|
||||
}
|
||||
else
|
||||
Benchmark.Run(startLat, startLon, endLat, endLon, regionSize, importPathVal[0], Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Benchmark"), logger);
|
||||
|
||||
Renderer.Render(r, 30000, "render.png");
|
||||
logger.LogInformation("All done!");
|
||||
|
||||
return 0;
|
Loading…
Reference in New Issue
Block a user