Skip to content

Commit

Permalink
Add TinyECS
Browse files Browse the repository at this point in the history
  • Loading branch information
xentripetal committed Apr 29, 2024
1 parent b992356 commit ce28dc6
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Tested frameworks:
- [Myriad.ECS](https://github.com/martindevans/Myriad.ECS)
- [RelEcs](https://github.com/Byteron/RelEcs)
- [Svelto.ECS](https://github.com/sebas77/Svelto.ECS)
- [TinyEcs](https://github.com/andreakarasho/TinyEcs)

Removed frameworks:
- [Entitas](https://github.com/sschmid/Entitas) removed because it was taking forever to initialize in the later tests when moved to net8, you can check older benchmark results [here](https://github.com/Doraku/Ecs.CSharp.Benchmark/tree/3574b2dfb948e941a208f77eaf9e94b73d58e6bf)
Expand Down
1 change: 1 addition & 0 deletions source/Ecs.CSharp.Benchmark/Categories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal static class Categories
public const string Morpeh = "Morpeh";
public const string FlecsNet = "FlecsNet";
public const string Fennecs = "Fennecs";
public const string TinyEcs = "TinyEcs";

public const string CreateEntity = "CreateEntity";
public const string System = "System";
Expand Down
24 changes: 24 additions & 0 deletions source/Ecs.CSharp.Benchmark/Contexts/TinyEcsBaseContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using TinyEcs;

namespace Ecs.CSharp.Benchmark.Contexts
{
namespace TinyEcs_Components
{
public record struct Component1(int Value);

public record struct Component2(int Value);

public record struct Component3(int Value);
}

public class TinyEcsBaseContext
{
public World World { get; }

public TinyEcsBaseContext()
{
World = new World();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using BenchmarkDotNet.Attributes;
using DefaultEcs;
using Ecs.CSharp.Benchmark.Contexts;
using Ecs.CSharp.Benchmark.Contexts.TinyEcs_Components;

namespace Ecs.CSharp.Benchmark
{
public partial class CreateEntityWithOneComponent
{
[Context]
private readonly TinyEcsBaseContext _tinyEcs;

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs()
{
for (int i = 0; i < EntityCount; ++i)
{
_tinyEcs.World.Entity().Set<Component1>();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using BenchmarkDotNet.Attributes;
using DefaultEcs;
using Ecs.CSharp.Benchmark.Contexts;
using Ecs.CSharp.Benchmark.Contexts.TinyEcs_Components;

namespace Ecs.CSharp.Benchmark
{
public partial class CreateEntityWithThreeComponents
{
[Context]
private readonly TinyEcsBaseContext _tinyEcs;

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs()
{
for (int i = 0; i < EntityCount; ++i)
{
_tinyEcs.World.Entity()
.Set<Component1>()
.Set<Component2>()
.Set<Component3>();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using BenchmarkDotNet.Attributes;
using DefaultEcs;
using Ecs.CSharp.Benchmark.Contexts;
using Ecs.CSharp.Benchmark.Contexts.TinyEcs_Components;

namespace Ecs.CSharp.Benchmark
{
public partial class CreateEntityWithTwoComponents
{
[Context]
private readonly TinyEcsBaseContext _tinyEcs;

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs()
{
for (int i = 0; i < EntityCount; ++i)
{
_tinyEcs.World.Entity()
.Set<Component1>()
.Set<Component2>();
}
}
}
}
1 change: 1 addition & 0 deletions source/Ecs.CSharp.Benchmark/Ecs.CSharp.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Roslynator.Analyzers" Version="4.10.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.10.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.10.0" PrivateAssets="all" />
<PackageReference Include="TinyEcs.Main" Version="1.2.0" />
</ItemGroup>

<ItemGroup Label="Benchmark">
Expand Down
42 changes: 42 additions & 0 deletions source/Ecs.CSharp.Benchmark/SystemWithOneComponent/TinyEcs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using BenchmarkDotNet.Attributes;
using Ecs.CSharp.Benchmark.Contexts;
using Ecs.CSharp.Benchmark.Contexts.TinyEcs_Components;
using TinyEcs;

namespace Ecs.CSharp.Benchmark
{
public partial class SystemWithOneComponent
{
[Context] private readonly TinyEcsContext _tinyEcs;

private sealed class TinyEcsContext : TinyEcsBaseContext
{
public TinyEcsContext(int entityCount, int entityPadding) : base()
{
for (int i = 0; i < entityCount; ++i)
{
for (int j = 0; j < entityPadding; ++j)
{
World.Entity();
}

World.Entity().Set<Component1>();
}
}
}

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs_Each()
{
_tinyEcs.World.Each((EntityView _, ref Component1 c1) => c1.Value++);
}

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs_EachJob()
{
_tinyEcs.World.EachJob((EntityView _, ref Component1 c1) => c1.Value++);
}
}
}
59 changes: 59 additions & 0 deletions source/Ecs.CSharp.Benchmark/SystemWithThreeComponents/TinyEcs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using BenchmarkDotNet.Attributes;
using Ecs.CSharp.Benchmark.Contexts;
using Ecs.CSharp.Benchmark.Contexts.TinyEcs_Components;
using TinyEcs;

namespace Ecs.CSharp.Benchmark
{
public partial class SystemWithThreeComponents
{
[Context] private readonly TinyEcsContext _tinyEcs;

private sealed class TinyEcsContext : TinyEcsBaseContext
{
public TinyEcsContext(int entityCount, int entityPadding) : base()
{
for (int i = 0; i < entityCount; ++i)
{
for (int j = 0; j < entityPadding; ++j)
{
var padding = World.Entity();
switch (j % 3)
{
case 0:
padding.Set(new Component1());
break;

case 1:
padding.Set(new Component2());
break;

case 2:
padding.Set(new Component3());
break;
}
}

World.Entity()
.Set(new Component1())
.Set(new Component2 { Value = 1 })
.Set(new Component3 { Value = 1 });
}
}
}

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs_Each()
{
_tinyEcs.World.Each((EntityView _, ref Component1 c1, ref Component2 c2, ref Component3 c3) => c1.Value += c2.Value + c3.Value);
}

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs_EachJob()
{
_tinyEcs.World.EachJob((EntityView _, ref Component1 c1, ref Component2 c2, ref Component3 c3) => c1.Value += c2.Value + c3.Value);
}
}
}
54 changes: 54 additions & 0 deletions source/Ecs.CSharp.Benchmark/SystemWithTwoComponents/TinyEcs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using BenchmarkDotNet.Attributes;
using Ecs.CSharp.Benchmark.Contexts;
using Ecs.CSharp.Benchmark.Contexts.TinyEcs_Components;
using TinyEcs;

namespace Ecs.CSharp.Benchmark
{
public partial class SystemWithTwoComponents
{
[Context] private readonly TinyEcsContext _tinyEcs;

private sealed class TinyEcsContext : TinyEcsBaseContext
{
public TinyEcsContext(int entityCount, int entityPadding) : base()
{
for (int i = 0; i < entityCount; ++i)
{
for (int j = 0; j < entityPadding; ++j)
{
var padding = World.Entity();
switch (j % 2)
{
case 0:
padding.Set(new Component1());
break;

case 1:
padding.Set(new Component2());
break;
}
}

World.Entity()
.Set(new Component1())
.Set(new Component2 { Value = 1 });
}
}
}

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs_Each()
{
_tinyEcs.World.Each((EntityView _, ref Component1 c1, ref Component2 c2) => c1.Value += c2.Value);
}

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs_EachJob()
{
_tinyEcs.World.EachJob((EntityView _, ref Component1 c1, ref Component2 c2) => c1.Value += c2.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using BenchmarkDotNet.Attributes;
using Ecs.CSharp.Benchmark.Contexts;
using Ecs.CSharp.Benchmark.Contexts.TinyEcs_Components;
using TinyEcs;

namespace Ecs.CSharp.Benchmark
{
public partial class SystemWithTwoComponentsMultipleComposition
{
[Context] private readonly TinyEcsContext _tinyEcs;

private sealed class TinyEcsContext : TinyEcsBaseContext
{

private record struct Padding1();
private record struct Padding2();
private record struct Padding3();
private record struct Padding4();

public TinyEcsContext(int entityCount) : base()
{
for (int i = 0; i < entityCount; ++i)
{
var entity = World.Entity();
entity.Set<Component1>();
entity.Set(new Component2 { Value = 1 });

switch (i % 4)
{
case 0:
entity.Set<Padding1>();
break;

case 1:
entity.Set<Padding2>();
break;

case 2:
entity.Set<Padding3>();
break;

case 3:
entity.Set<Padding4>();
break;
}
}
}
}

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs_Each()
{
_tinyEcs.World.Each((EntityView _, ref Component1 c1, ref Component2 c2) => c1.Value += c2.Value);
}

[BenchmarkCategory(Categories.TinyEcs)]
[Benchmark]
public void TinyEcs_EachJob()
{
_tinyEcs.World.EachJob((EntityView _, ref Component1 c1, ref Component2 c2) => c1.Value += c2.Value);
}
}
}

0 comments on commit ce28dc6

Please sign in to comment.