-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added benchmark for Morpeh ECS framework
- Loading branch information
Showing
11 changed files
with
614 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using Scellecs.Morpeh; | ||
|
||
namespace Ecs.CSharp.Benchmark.Context | ||
{ | ||
internal class MorpehBaseContext : IDisposable | ||
{ | ||
public struct Component1 : IComponent | ||
{ | ||
public int Value; | ||
} | ||
|
||
public struct Component2 : IComponent | ||
{ | ||
public int Value; | ||
} | ||
|
||
public struct Component3 : IComponent | ||
{ | ||
public int Value; | ||
} | ||
|
||
public World World { get; } | ||
|
||
protected MorpehBaseContext() | ||
{ | ||
World = World.Create(); | ||
} | ||
|
||
public virtual void Dispose() | ||
{ | ||
World.Dispose(); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
source/Ecs.CSharp.Benchmark/CreateEntityWithOneComponent/Morpeh.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Ecs.CSharp.Benchmark.Context; | ||
using Scellecs.Morpeh; | ||
|
||
namespace Ecs.CSharp.Benchmark | ||
{ | ||
public partial class CreateEntityWithOneComponent | ||
{ | ||
[Context] | ||
private readonly MorpehBaseContext _context; | ||
|
||
[BenchmarkCategory(Categories.Morpeh)] | ||
[Benchmark] | ||
public void Morpeh_Direct() | ||
{ | ||
World world = _context.World; | ||
for (int i = 0; i < EntityCount; ++i) | ||
{ | ||
world.CreateEntity().AddComponent<MorpehBaseContext.Component1>(); | ||
} | ||
|
||
world.Commit(); | ||
} | ||
|
||
[BenchmarkCategory(Categories.Morpeh)] | ||
[Benchmark] | ||
public void Morpeh_Stash() | ||
{ | ||
World world = _context.World; | ||
Stash<MorpehBaseContext.Component1> stash1 = world.GetStash<MorpehBaseContext.Component1>(); | ||
for (int i = 0; i < EntityCount; ++i) | ||
{ | ||
Entity entity = world.CreateEntity(); | ||
stash1.Add(entity); | ||
} | ||
|
||
world.Commit(); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
source/Ecs.CSharp.Benchmark/CreateEntityWithThreeComponents/Morpeh.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Ecs.CSharp.Benchmark.Context; | ||
using Scellecs.Morpeh; | ||
|
||
namespace Ecs.CSharp.Benchmark | ||
{ | ||
public partial class CreateEntityWithThreeComponents | ||
{ | ||
[Context] | ||
private readonly MorpehBaseContext _context; | ||
|
||
[BenchmarkCategory(Categories.Morpeh)] | ||
[Benchmark] | ||
public void Morpeh_Direct() | ||
{ | ||
World world = _context.World; | ||
for (int i = 0; i < EntityCount; ++i) | ||
{ | ||
world.CreateEntity().AddComponent<MorpehBaseContext.Component1>(); | ||
world.CreateEntity().AddComponent<MorpehBaseContext.Component2>(); | ||
} | ||
|
||
world.Commit(); | ||
} | ||
|
||
[BenchmarkCategory(Categories.Morpeh)] | ||
[Benchmark] | ||
public void Morpeh_Stash() | ||
{ | ||
World world = _context.World; | ||
Stash<MorpehBaseContext.Component1> stash1 = world.GetStash<MorpehBaseContext.Component1>(); | ||
Stash<MorpehBaseContext.Component2> stash2 = world.GetStash<MorpehBaseContext.Component2>(); | ||
for (int i = 0; i < EntityCount; ++i) | ||
{ | ||
Entity entity = world.CreateEntity(); | ||
stash1.Add(entity); | ||
stash2.Add(entity); | ||
} | ||
|
||
world.Commit(); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
source/Ecs.CSharp.Benchmark/CreateEntityWithTwoComponents/Morpeh.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Ecs.CSharp.Benchmark.Context; | ||
using Scellecs.Morpeh; | ||
|
||
namespace Ecs.CSharp.Benchmark | ||
{ | ||
public partial class CreateEntityWithTwoComponents | ||
{ | ||
[Context] | ||
private readonly MorpehBaseContext _context; | ||
|
||
[BenchmarkCategory(Categories.Morpeh)] | ||
[Benchmark] | ||
public void Morpeh_Direct() | ||
{ | ||
World world = _context.World; | ||
for (int i = 0; i < EntityCount; ++i) | ||
{ | ||
world.CreateEntity().AddComponent<MorpehBaseContext.Component1>(); | ||
world.CreateEntity().AddComponent<MorpehBaseContext.Component2>(); | ||
world.CreateEntity().AddComponent<MorpehBaseContext.Component3>(); | ||
} | ||
|
||
world.Commit(); | ||
} | ||
|
||
[BenchmarkCategory(Categories.Morpeh)] | ||
[Benchmark] | ||
public void Morpeh_Stash() | ||
{ | ||
World world = _context.World; | ||
Stash<MorpehBaseContext.Component1> stash1 = world.GetStash<MorpehBaseContext.Component1>(); | ||
Stash<MorpehBaseContext.Component2> stash2 = world.GetStash<MorpehBaseContext.Component2>(); | ||
Stash<MorpehBaseContext.Component3> stash3 = world.GetStash<MorpehBaseContext.Component3>(); | ||
for (int i = 0; i < EntityCount; ++i) | ||
{ | ||
Entity entity = world.CreateEntity(); | ||
stash1.Add(entity); | ||
stash2.Add(entity); | ||
stash3.Add(entity); | ||
} | ||
|
||
world.Commit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
source/Ecs.CSharp.Benchmark/SystemWithOneComponent/Morpeh.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using Ecs.CSharp.Benchmark.Context; | ||
using Scellecs.Morpeh; | ||
|
||
namespace Ecs.CSharp.Benchmark | ||
{ | ||
public partial class SystemWithOneComponent | ||
{ | ||
private sealed class MorpehContext : MorpehBaseContext | ||
{ | ||
private sealed class DirectSystem : ISystem | ||
{ | ||
public World World { get; set; } | ||
private Filter _filter; | ||
|
||
public void OnAwake() | ||
{ | ||
_filter = World.Filter.With<Component1>(); | ||
} | ||
|
||
public void OnUpdate(float deltaTime) | ||
{ | ||
foreach (Entity entity in _filter) | ||
{ | ||
++entity.GetComponent<Component1>().Value; | ||
} | ||
} | ||
|
||
void IDisposable.Dispose() { } | ||
} | ||
|
||
private sealed class StashSystem : ISystem | ||
{ | ||
public World World { get; set; } | ||
private Stash<Component1> _stash1; | ||
private Filter _filter; | ||
|
||
public void OnAwake() | ||
{ | ||
_stash1 = World.GetStash<Component1>(); | ||
_filter = World.Filter.With<Component1>(); | ||
} | ||
|
||
public void OnUpdate(float deltaTime) | ||
{ | ||
foreach (Entity entity in _filter) | ||
{ | ||
++_stash1.Get(entity).Value; | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_stash1.Dispose(); | ||
} | ||
} | ||
|
||
public ISystem MonoThreadDirectSystem { get; } | ||
public ISystem MonoThreadStashSystem { get; } | ||
|
||
public MorpehContext(int entityCount, int entityPadding) | ||
{ | ||
MonoThreadDirectSystem = new DirectSystem { World = World }; | ||
MonoThreadDirectSystem.OnAwake(); | ||
|
||
MonoThreadStashSystem = new StashSystem { World = World }; | ||
MonoThreadStashSystem.OnAwake(); | ||
|
||
for (int i = 0; i < entityCount; ++i) | ||
{ | ||
for (int j = 0; j < entityPadding; ++j) | ||
{ | ||
World.CreateEntity(); | ||
} | ||
|
||
World.CreateEntity().AddComponent<Component1>(); | ||
} | ||
|
||
World.Commit(); | ||
} | ||
} | ||
|
||
[Context] | ||
private readonly MorpehContext _context; | ||
|
||
[BenchmarkCategory(Categories.Morpeh)] | ||
[Benchmark] | ||
public void Morpeh_Direct() => _context.MonoThreadDirectSystem.OnUpdate(0f); | ||
|
||
[BenchmarkCategory(Categories.Morpeh)] | ||
[Benchmark] | ||
public void Morpeh_Stash() => _context.MonoThreadStashSystem.OnUpdate(0f); | ||
} | ||
} |
Oops, something went wrong.