Fix MapLoadBenchmark

This commit is contained in:
ElectroJr
2024-12-23 18:02:46 +13:00
parent d47e72d7c2
commit 43e6fd57d4

View File

@@ -6,12 +6,13 @@ using BenchmarkDotNet.Attributes;
using Content.IntegrationTests; using Content.IntegrationTests;
using Content.IntegrationTests.Pair; using Content.IntegrationTests.Pair;
using Content.Server.Maps; using Content.Server.Maps;
using Robust.Server.GameObjects;
using Robust.Shared; using Robust.Shared;
using Robust.Shared.Analyzers; using Robust.Shared.Analyzers;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Benchmarks; namespace Content.Benchmarks;
@@ -20,7 +21,7 @@ public class MapLoadBenchmark
{ {
private TestPair _pair = default!; private TestPair _pair = default!;
private MapLoaderSystem _mapLoader = default!; private MapLoaderSystem _mapLoader = default!;
private IMapManager _mapManager = default!; private SharedMapSystem _mapSys = default!;
[GlobalSetup] [GlobalSetup]
public void Setup() public void Setup()
@@ -36,7 +37,7 @@ public class MapLoadBenchmark
.ToDictionary(x => x.ID, x => x.MapPath.ToString()); .ToDictionary(x => x.ID, x => x.MapPath.ToString());
_mapLoader = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<MapLoaderSystem>(); _mapLoader = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<MapLoaderSystem>();
_mapManager = server.ResolveDependency<IMapManager>(); _mapSys = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<SharedMapSystem>();
} }
[GlobalCleanup] [GlobalCleanup]
@@ -52,17 +53,19 @@ public class MapLoadBenchmark
public string Map; public string Map;
public Dictionary<string, string> Paths; public Dictionary<string, string> Paths;
private MapId _mapId;
[Benchmark] [Benchmark]
public async Task LoadMap() public async Task LoadMap()
{ {
var mapPath = Paths[Map]; var mapPath = new ResPath(Paths[Map]);
var server = _pair.Server; var server = _pair.Server;
await server.WaitPost(() => await server.WaitPost(() =>
{ {
var success = _mapLoader.TryLoad(new MapId(10), mapPath, out _); var success = _mapLoader.TryLoadMap(mapPath, out var map, out _);
if (!success) if (!success)
throw new Exception("Map load failed"); throw new Exception("Map load failed");
_mapId = map.Value.Comp.MapId;
}); });
} }
@@ -70,9 +73,7 @@ public class MapLoadBenchmark
public void IterationCleanup() public void IterationCleanup()
{ {
var server = _pair.Server; var server = _pair.Server;
server.WaitPost(() => server.WaitPost(() => _mapSys.DeleteMap(_mapId))
{ .Wait();
_mapManager.DeleteMap(new MapId(10));
}).Wait();
} }
} }