mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-06-09 13:26:34 +02:00
d42adbf05d
* Pass 1. * i'm FREE * Prevent hangups. * okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing. * sigh. * fix singular trigger bug so LatheTest doesn't flake. * Remove SystemAttribute usage. * Poke * I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls. * Change the faulty store test into two tests, one of which is ignored for failing.
150 lines
4.1 KiB
C#
150 lines
4.1 KiB
C#
#nullable enable
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading.Tasks;
|
|
using BenchmarkDotNet.Attributes;
|
|
using Content.IntegrationTests;
|
|
using Content.IntegrationTests.Pair;
|
|
using Robust.Shared;
|
|
using Robust.Shared.Analyzers;
|
|
using Robust.Shared.GameObjects;
|
|
|
|
namespace Content.Benchmarks;
|
|
|
|
[Virtual]
|
|
public class RaiseEventBenchmark
|
|
{
|
|
private TestPair _pair = default!;
|
|
private BenchSystem _sys = default!;
|
|
|
|
[GlobalSetup]
|
|
public void Setup()
|
|
{
|
|
ProgramShared.PathOffset = "../../../../";
|
|
PoolManager.Startup(typeof(BenchSystem).Assembly);
|
|
_pair = PoolManager.GetServerClient(testContext: new ExternalTestContext("Benchmark", StreamWriter.Null)).GetAwaiter().GetResult();
|
|
var entMan = _pair.Server.EntMan;
|
|
var fact = _pair.Server.ResolveDependency<IComponentFactory>();
|
|
var bus = (EntityEventBus)entMan.EventBus;
|
|
_sys = entMan.System<BenchSystem>();
|
|
|
|
_pair.Server.WaitPost(() =>
|
|
{
|
|
var uid = entMan.Spawn();
|
|
_sys.Ent = new(uid, entMan.GetComponent<TransformComponent>(uid));
|
|
_sys.Ent2 = new(_sys.Ent.Owner, _sys.Ent.Comp);
|
|
_sys.NetId = fact.GetRegistration<TransformComponent>().NetID!.Value;
|
|
_sys.EvSubs = bus.GetNetCompEventHandlers<BenchSystem.BenchEv>();
|
|
})
|
|
.GetAwaiter()
|
|
.GetResult();
|
|
}
|
|
|
|
[GlobalCleanup]
|
|
public async Task Cleanup()
|
|
{
|
|
await _pair.DisposeAsync();
|
|
PoolManager.Shutdown();
|
|
}
|
|
|
|
[Benchmark(Baseline = true)]
|
|
public int RaiseEvent()
|
|
{
|
|
return _sys.RaiseEvent();
|
|
}
|
|
|
|
[Benchmark]
|
|
public int RaiseCompEvent()
|
|
{
|
|
return _sys.RaiseCompEvent();
|
|
}
|
|
|
|
[Benchmark]
|
|
public int RaiseICompEvent()
|
|
{
|
|
return _sys.RaiseICompEvent();
|
|
}
|
|
|
|
[Benchmark]
|
|
public int RaiseNetEvent()
|
|
{
|
|
return _sys.RaiseNetIdEvent();
|
|
}
|
|
|
|
[Benchmark]
|
|
public int RaiseCSharpEvent()
|
|
{
|
|
return _sys.CSharpEvent();
|
|
}
|
|
|
|
public sealed class BenchSystem : EntitySystem
|
|
{
|
|
public Entity<TransformComponent> Ent;
|
|
public Entity<IComponent> Ent2;
|
|
|
|
public delegate void EntityEventHandler(EntityUid uid, TransformComponent comp, ref BenchEv ev);
|
|
|
|
public event EntityEventHandler? OnCSharpEvent;
|
|
public ushort NetId;
|
|
internal EntityEventBus.DirectedEventHandler?[] EvSubs = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<TransformComponent, BenchEv>(OnEvent);
|
|
OnCSharpEvent += OnEvent;
|
|
}
|
|
|
|
public int RaiseEvent()
|
|
{
|
|
var ev = new BenchEv();
|
|
RaiseLocalEvent(Ent.Owner, ref ev);
|
|
return ev.N;
|
|
}
|
|
|
|
public int RaiseCompEvent()
|
|
{
|
|
var ev = new BenchEv();
|
|
RaiseComponentEvent(Ent.Owner, Ent.Comp, ref ev);
|
|
return ev.N;
|
|
}
|
|
|
|
public int RaiseICompEvent()
|
|
{
|
|
// Raise with an IComponent instead of concrete type
|
|
var ev = new BenchEv();
|
|
RaiseComponentEvent(Ent2.Owner, Ent2.Comp, ref ev);
|
|
return ev.N;
|
|
}
|
|
|
|
public int RaiseNetIdEvent()
|
|
{
|
|
// Raise a "IComponent" event using a net-id index delegate array (for PVS & client game-state events)
|
|
var ev = new BenchEv();
|
|
ref var unitEv = ref Unsafe.As<BenchEv, EntityEventBus.Unit>(ref ev);
|
|
EvSubs[NetId]?.Invoke(Ent2.Owner, Ent2.Comp, ref unitEv);
|
|
return ev.N;
|
|
}
|
|
|
|
public int CSharpEvent()
|
|
{
|
|
var ev = new BenchEv();
|
|
OnCSharpEvent?.Invoke(Ent.Owner, Ent.Comp, ref ev);
|
|
return ev.N;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
|
private void OnEvent(EntityUid uid, TransformComponent component, ref BenchEv args)
|
|
{
|
|
args.N += uid.Id;
|
|
}
|
|
|
|
[ByRefEvent]
|
|
[ComponentEvent(Exclusive = false)]
|
|
public struct BenchEv
|
|
{
|
|
public int N;
|
|
}
|
|
}
|
|
}
|