Files
wwdpublic/Content.Benchmarks/SpawnEquipDeleteBenchmark.cs
VMSolidus 08822e34ba Cherry-Pick Antag Refactor (#734)
This cherry-pick's Wizden's Antag Refactor, which is needed for all
future antag updates, as well as for me to cherry-pick over Cultists(Who
are going to need some editing to fit the antag refactor), Changelings,
Heretics, and Wizards. I actually selected the White-Dream-Public
version of the Antag Refactor, due to it having commits made tailored to
our repository, so it comes prepackaged with all the changes necessary
for our repo-specific content.

https://github.com/frosty-dev/ss14-wwdp/pull/10

Signed-off-by: Timemaster99 <57200767+Timemaster99@users.noreply.github.com>
Co-authored-by: ThereDrD <88589686+ThereDrD0@users.noreply.github.com>
Co-authored-by: Jeff <velcroboy333@hotmail.com>
Co-authored-by: Timemaster99 <57200767+Timemaster99@users.noreply.github.com>
Co-authored-by: Timemaster99 <elijahrobot@gmail.com>
Co-authored-by: luckywill339@gmail.com <luckywill339@gmail.com>
Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com>
Co-authored-by: Azzy <azzydev@icloud.com>
2024-08-15 10:11:48 -07:00

67 lines
1.9 KiB
C#

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);
server.EntMan.DeleteEntity(_entity);
}
});
}
}