Benchmarks project along with a component manager benchmark. (#251)
This commit is contained in:
committed by
GitHub
parent
400778eb73
commit
dd13d969b2
73
Content.Benchmarks/ComponentManagerGetAllComponents.cs
Normal file
73
Content.Benchmarks/ComponentManagerGetAllComponents.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Moq;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Benchmarks
|
||||
{
|
||||
public class ComponentManagerGetAllComponents
|
||||
{
|
||||
private readonly List<IEntity> _entities = new List<IEntity>();
|
||||
|
||||
private IComponentManager _componentManager;
|
||||
|
||||
[Params(500, 1000, 5000)] public int N { get; set; }
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
// Initialize component manager.
|
||||
IoCManager.InitThread();
|
||||
|
||||
IoCManager.Register<IComponentManager, ComponentManager>();
|
||||
|
||||
var dummyReg = new Mock<IComponentRegistration>();
|
||||
dummyReg.SetupGet(p => p.Name).Returns("Dummy");
|
||||
dummyReg.SetupGet(p => p.Type).Returns(typeof(DummyComponent));
|
||||
dummyReg.SetupGet(p => p.NetID).Returns((uint?) null);
|
||||
dummyReg.SetupGet(p => p.NetworkSynchronizeExistence).Returns(false);
|
||||
dummyReg.SetupGet(p => p.References).Returns(new Type[] {typeof(DummyComponent)});
|
||||
|
||||
var componentFactory = new Mock<IComponentFactory>();
|
||||
componentFactory.Setup(p => p.GetComponent<DummyComponent>()).Returns(new DummyComponent());
|
||||
componentFactory.Setup(p => p.GetRegistration(It.IsAny<DummyComponent>())).Returns(dummyReg.Object);
|
||||
|
||||
IoCManager.RegisterInstance<IComponentFactory>(componentFactory.Object);
|
||||
|
||||
IoCManager.BuildGraph();
|
||||
|
||||
_componentManager = IoCManager.Resolve<IComponentManager>();
|
||||
|
||||
// Initialize N entities with one component.
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
var entity = new Entity();
|
||||
entity.SetUid(new EntityUid(i + 1));
|
||||
_entities.Add(entity);
|
||||
|
||||
_componentManager.AddComponent<DummyComponent>(entity);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int Run()
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
foreach (var _ in _componentManager.GetAllComponents<DummyComponent>())
|
||||
{
|
||||
count += 1;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private class DummyComponent : Component
|
||||
{
|
||||
public override string Name => "Dummy";
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Content.Benchmarks/Content.Benchmarks.csproj
Normal file
25
Content.Benchmarks/Content.Benchmarks.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<OutputPath>..\bin\Content.Benchmarks\</OutputPath>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<Platforms>x86;x64</Platforms>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Content.Client\Content.Client.csproj" />
|
||||
<ProjectReference Include="..\Content.Server\Content.Server.csproj" />
|
||||
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
|
||||
<ProjectReference Include="..\Content.Tests\Content.Tests.csproj" />
|
||||
<ProjectReference Include="..\Content.IntegrationTests\Content.IntegrationTests.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.UnitTesting\Robust.UnitTesting.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
13
Content.Benchmarks/Program.cs
Normal file
13
Content.Benchmarks/Program.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Running;
|
||||
|
||||
namespace Content.Benchmarks
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BenchmarkRunner.Run<ComponentManagerGetAllComponents>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robust.Shared", "RobustTool
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Content.IntegrationTests", "Content.IntegrationTests\Content.IntegrationTests.csproj", "{AB7AF1C8-30FF-4436-9DF0-179BE5B0C132}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Content.Benchmarks", "Content.Benchmarks\Content.Benchmarks.csproj", "{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@@ -141,6 +143,14 @@ Global
|
||||
{F0ADA779-40B8-4F7E-BA6C-CDB19F3065D9}.Release|x64.Build.0 = Release|x64
|
||||
{F0ADA779-40B8-4F7E-BA6C-CDB19F3065D9}.Release|x86.ActiveCfg = Release|x86
|
||||
{F0ADA779-40B8-4F7E-BA6C-CDB19F3065D9}.Release|x86.Build.0 = Release|x86
|
||||
{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}.Debug|x64.Build.0 = Debug|x64
|
||||
{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}.Debug|x86.Build.0 = Debug|x86
|
||||
{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}.Release|x64.ActiveCfg = Release|x64
|
||||
{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}.Release|x64.Build.0 = Release|x64
|
||||
{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}.Release|x86.ActiveCfg = Release|x86
|
||||
{7AC832A1-2461-4EB5-AC26-26F6AFFA9E46}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user