Skip to content

Instantly share code, notes, and snippets.

@VirtualMaestro
Created September 21, 2019 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VirtualMaestro/77adc4ee59108eb7122617446abcd716 to your computer and use it in GitHub Desktop.
Save VirtualMaestro/77adc4ee59108eb7122617446abcd716 to your computer and use it in GitHub Desktop.
Test Leo Ecs2
using System;
using System.Diagnostics;
namespace Ecs2
{
internal class Program
{
class C1 {
public float a;
public float b;
public float c;
public float d;
}
struct S1 {
public float a;
public float b;
public float c;
public float d;
}
const int EntitiesCount = 100000;
const int SystemsCount = 50;
const int TestIterations = 30;
public static void Main(string[] args)
{
Test1();
Test2();
}
static void Test1 () {
var world = new Leopotam.Ecs.EcsWorld ();
var filter = (Leopotam.Ecs.EcsFilter<C1>) world.GetFilter (typeof (Leopotam.Ecs.EcsFilter<C1>));
for (var i = 0; i < EntitiesCount; i++) {
world.CreateEntityWith<C1> (out _);
}
world.ProcessDelayedUpdates ();
var sw = new Stopwatch ();
var result = 0;
for (var testIt = 0; testIt < TestIterations; testIt++) {
sw.Reset ();
sw.Start ();
for (int ii = 0; ii < SystemsCount; ii++) {
foreach (var idx in filter) {
var c = filter.Components1[idx];
c.a += 1f;
}
world.ProcessDelayedUpdates ();
}
sw.Stop ();
result += sw.Elapsed.Milliseconds;
}
world.Dispose ();
Console.WriteLine("ecs1: " + (result / (float) TestIterations));
}
static void Test2 () {
var world = new Leopotam.Ecs2.EcsWorld ();
var filter = (Leopotam.Ecs2.EcsFilter<S1>) world.GetFilter (typeof (Leopotam.Ecs2.EcsFilter<S1>));
for (var i = 0; i < EntitiesCount; i++) {
world.NewEntity ().Set<S1> ();
}
var sw = new Stopwatch ();
var result = 0;
for (var testIt = 0; testIt < TestIterations; testIt++) {
sw.Reset ();
sw.Start ();
for (int ii = 0; ii < SystemsCount; ii++) {
foreach (var idx in filter) {
ref var c = ref filter.Get1 (idx);
c.a += 1f;
}
}
sw.Stop ();
result += sw.Elapsed.Milliseconds;
}
world.Destroy ();
Console.WriteLine("ecs2: " + (result / (float) TestIterations));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment