Add SpawnEquipDeleteBenchmark (#19566)
This commit is contained in:
@@ -59,6 +59,7 @@ public class DeviceNetworkingBenchmark
|
|||||||
public async Task SetupAsync()
|
public async Task SetupAsync()
|
||||||
{
|
{
|
||||||
ProgramShared.PathOffset = "../../../../";
|
ProgramShared.PathOffset = "../../../../";
|
||||||
|
PoolManager.Startup(typeof(DeviceNetworkingBenchmark).Assembly);
|
||||||
_pair = await PoolManager.GetServerClient();
|
_pair = await PoolManager.GetServerClient();
|
||||||
var server = _pair.Server;
|
var server = _pair.Server;
|
||||||
|
|
||||||
@@ -91,6 +92,7 @@ public class DeviceNetworkingBenchmark
|
|||||||
public async Task Cleanup()
|
public async Task Cleanup()
|
||||||
{
|
{
|
||||||
await _pair.DisposeAsync();
|
await _pair.DisposeAsync();
|
||||||
|
PoolManager.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Benchmark(Baseline = true, Description = "Entity Events")]
|
[Benchmark(Baseline = true, Description = "Entity Events")]
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class MapLoadBenchmark
|
|||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
ProgramShared.PathOffset = "../../../../";
|
ProgramShared.PathOffset = "../../../../";
|
||||||
|
PoolManager.Startup(null);
|
||||||
|
|
||||||
_pair = PoolManager.GetServerClient().GetAwaiter().GetResult();
|
_pair = PoolManager.GetServerClient().GetAwaiter().GetResult();
|
||||||
var server = _pair.Server;
|
var server = _pair.Server;
|
||||||
@@ -42,6 +43,7 @@ public class MapLoadBenchmark
|
|||||||
public async Task Cleanup()
|
public async Task Cleanup()
|
||||||
{
|
{
|
||||||
await _pair.DisposeAsync();
|
await _pair.DisposeAsync();
|
||||||
|
PoolManager.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<string> MapsSource { get; set; }
|
public static IEnumerable<string> MapsSource { get; set; }
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BenchmarkDotNet.Configs;
|
|
||||||
using BenchmarkDotNet.Running;
|
using BenchmarkDotNet.Running;
|
||||||
using Content.IntegrationTests;
|
using Content.IntegrationTests;
|
||||||
using Content.Server.Maps;
|
using Content.Server.Maps;
|
||||||
|
#if DEBUG
|
||||||
|
using BenchmarkDotNet.Configs;
|
||||||
|
#else
|
||||||
using Robust.Benchmarks.Configs;
|
using Robust.Benchmarks.Configs;
|
||||||
|
#endif
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Benchmarks
|
namespace Content.Benchmarks
|
||||||
@@ -25,6 +28,7 @@ namespace Content.Benchmarks
|
|||||||
var gameMaps = pair.Server.ResolveDependency<IPrototypeManager>().EnumeratePrototypes<GameMapPrototype>().ToList();
|
var gameMaps = pair.Server.ResolveDependency<IPrototypeManager>().EnumeratePrototypes<GameMapPrototype>().ToList();
|
||||||
MapLoadBenchmark.MapsSource = gameMaps.Select(x => x.ID);
|
MapLoadBenchmark.MapsSource = gameMaps.Select(x => x.ID);
|
||||||
await pair.CleanReturnAsync();
|
await pair.CleanReturnAsync();
|
||||||
|
PoolManager.Shutdown();
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
@@ -35,8 +39,6 @@ namespace Content.Benchmarks
|
|||||||
var config = Environment.GetEnvironmentVariable("ROBUST_BENCHMARKS_ENABLE_SQL") != null ? DefaultSQLConfig.Instance : null;
|
var config = Environment.GetEnvironmentVariable("ROBUST_BENCHMARKS_ENABLE_SQL") != null ? DefaultSQLConfig.Instance : null;
|
||||||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
|
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PoolManager.Shutdown();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
66
Content.Benchmarks/SpawnEquipDeleteBenchmark.cs
Normal file
66
Content.Benchmarks/SpawnEquipDeleteBenchmark.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using Content.IntegrationTests;
|
||||||
|
using Content.IntegrationTests.Pair;
|
||||||
|
using Content.Server.Station.Systems;
|
||||||
|
using Content.Shared.Roles;
|
||||||
|
using Robust.Shared;
|
||||||
|
using Robust.Shared.Analyzers;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
|
||||||
|
namespace Content.Benchmarks;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This benchmarks spawns several humans, gives them captain equipment and then deletes them.
|
||||||
|
/// This measures performance for spawning, deletion, containers, and inventory code.
|
||||||
|
/// </summary>
|
||||||
|
[Virtual, MemoryDiagnoser]
|
||||||
|
public class SpawnEquipDeleteBenchmark
|
||||||
|
{
|
||||||
|
private TestPair _pair = default!;
|
||||||
|
private StationSpawningSystem _spawnSys = default!;
|
||||||
|
private const string Mob = "MobHuman";
|
||||||
|
private StartingGearPrototype _gear = default!;
|
||||||
|
private EntityUid _entity;
|
||||||
|
private EntityCoordinates _coords;
|
||||||
|
|
||||||
|
[Params(1, 4, 16, 64)]
|
||||||
|
public int N;
|
||||||
|
|
||||||
|
[GlobalSetup]
|
||||||
|
public async Task SetupAsync()
|
||||||
|
{
|
||||||
|
ProgramShared.PathOffset = "../../../../";
|
||||||
|
PoolManager.Startup(null);
|
||||||
|
_pair = await PoolManager.GetServerClient();
|
||||||
|
var server = _pair.Server;
|
||||||
|
|
||||||
|
var mapData = await _pair.CreateTestMap();
|
||||||
|
_coords = mapData.GridCoords;
|
||||||
|
_spawnSys = server.System<StationSpawningSystem>();
|
||||||
|
_gear = server.ProtoMan.Index<StartingGearPrototype>("CaptainGear");
|
||||||
|
}
|
||||||
|
|
||||||
|
[GlobalCleanup]
|
||||||
|
public async Task Cleanup()
|
||||||
|
{
|
||||||
|
await _pair.DisposeAsync();
|
||||||
|
PoolManager.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public async Task SpawnDeletePlayer()
|
||||||
|
{
|
||||||
|
await _pair.Server.WaitPost(() =>
|
||||||
|
{
|
||||||
|
var server = _pair.Server;
|
||||||
|
for (var i = 0; i < N; i++)
|
||||||
|
{
|
||||||
|
_entity = server.EntMan.SpawnAttachedTo(Mob, _coords);
|
||||||
|
_spawnSys.EquipStartingGear(_entity, _gear, null);
|
||||||
|
server.EntMan.DeleteEntity(_entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,11 @@ public sealed partial class TestPair
|
|||||||
instance.ProtoMan.LoadString(file, changed: changed);
|
instance.ProtoMan.LoadString(file, changed: changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
await instance.WaitPost(() => instance.ProtoMan.ReloadPrototypes(changed));
|
await instance.WaitPost(() =>
|
||||||
|
{
|
||||||
|
instance.ProtoMan.ResolveResults();
|
||||||
|
instance.ProtoMan.ReloadPrototypes(changed);
|
||||||
|
});
|
||||||
|
|
||||||
foreach (var (kind, ids) in changed)
|
foreach (var (kind, ids) in changed)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user