-
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.
- Loading branch information
1 parent
b992356
commit ce28dc6
Showing
11 changed files
with
320 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
24 changes: 24 additions & 0 deletions
24
source/Ecs.CSharp.Benchmark/Contexts/TinyEcsBaseContext.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,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(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
source/Ecs.CSharp.Benchmark/CreateEntityWithOneComponent/TinyEcs.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,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>(); | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
source/Ecs.CSharp.Benchmark/CreateEntityWithThreeComponents/TinyEcs.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,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>(); | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
source/Ecs.CSharp.Benchmark/CreateEntityWithTwoComponents/TinyEcs.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,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>(); | ||
} | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
source/Ecs.CSharp.Benchmark/SystemWithOneComponent/TinyEcs.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,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
59
source/Ecs.CSharp.Benchmark/SystemWithThreeComponents/TinyEcs.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,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
54
source/Ecs.CSharp.Benchmark/SystemWithTwoComponents/TinyEcs.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,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); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
source/Ecs.CSharp.Benchmark/SystemWithTwoComponentsMultipleComposition/TinyEcs.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,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); | ||
} | ||
} | ||
} |