From 364f2ed2c2c118e405caabda7a4751b68d09548d Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 5 Dec 2024 12:10:34 +0700 Subject: [PATCH] add tiny-ecs cache/nocache bench variants --- develop/unbench/evolved_unbench.lua | 8 ++-- develop/unbench/tiny_unbench.lua | 66 ++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/develop/unbench/evolved_unbench.lua b/develop/unbench/evolved_unbench.lua index e56a2a0..80d484c 100644 --- a/develop/unbench/evolved_unbench.lua +++ b/develop/unbench/evolved_unbench.lua @@ -131,7 +131,7 @@ end) ---@param b evolved.entity ---@param A evolved.query ---@param B evolved.query -common.describe('Entity Cycle Simple', function(a, b, A, B) +common.describe('Entity Cycle (Simple)', function(a, b, A, B) ---@type any[] local to_create = {} @@ -177,7 +177,7 @@ end) ---@param b evolved.entity ---@param A evolved.query ---@param B evolved.query -common.describe('Entity Cycle Batched', function(a, b, A, B) +common.describe('Entity Cycle (Batched)', function(a, b, A, B) ---@type any[] local to_create = {} @@ -210,7 +210,7 @@ end) ---@param b evolved.entity ---@param A evolved.query ---@param AB evolved.query -common.describe('Add / Remove Simple', function(b, A, AB) +common.describe('Add / Remove (Simple)', function(b, A, AB) ---@type evolved.entity[] local to_insert = {} @@ -255,7 +255,7 @@ end) ---@param b evolved.entity ---@param A evolved.query ---@param AB evolved.query -common.describe('Add / Remove Batched', function(b, A, AB) +common.describe('Add / Remove (Batched)', function(b, A, AB) assert(10000 == evo.registry.query_insert(A, b)) assert(10000 == evo.registry.query_remove(AB, b)) end, function() diff --git a/develop/unbench/tiny_unbench.lua b/develop/unbench/tiny_unbench.lua index 179cdea..9551f4b 100644 --- a/develop/unbench/tiny_unbench.lua +++ b/develop/unbench/tiny_unbench.lua @@ -104,7 +104,7 @@ end, function() return w end) -common.describe('Entity Cycle', function(w) +common.describe('Entity Cycle (Cache)', function(w) tiny.update(w, 0.016) end, function() local w = tiny.world() @@ -130,7 +130,35 @@ end, function() return w end) -common.describe('Add / Remove', function(w) +common.describe('Entity Cycle (No Cache)', function(w) + tiny.update(w, 0.016) +end, function() + local w = tiny.world() + + for _ = 1, 1000 do + tiny.addEntity(w, { a = 0 }) + end + + local A = tiny.processingSystem() + A.nocache = true + A.filter = tiny.requireAll('a') + A.process = function(_, e) tiny.addEntity(w, { b = e.a }) end + A.postProcess = function(_) tiny.refresh(w) end + + local B = tiny.processingSystem() + B.nocache = true + B.filter = tiny.requireAll('b') + B.process = function(_, e) tiny.removeEntity(w, e) end + B.postProcess = function(_) tiny.refresh(w) end + + tiny.addSystem(w, A) + tiny.addSystem(w, B) + + tiny.refresh(w) + return w +end) + +common.describe('Add / Remove (Cache)', function(w) tiny.update(w, 0.016) end, function() local w = tiny.world() @@ -161,3 +189,37 @@ end, function() tiny.refresh(w) return w end) + +common.describe('Add / Remove (No Cache)', function(w) + tiny.update(w, 0.016) +end, function() + local w = tiny.world() + + for _ = 1, 10000 do + tiny.addEntity(w, { a = 0 }) + end + + local A = tiny.processingSystem() + A.nocache = true + A.filter = tiny.requireAll('a') + A.process = function(_, e) + e.b = 0 + tiny.addEntity(w, e) + end + A.postProcess = function(_) tiny.refresh(w) end + + local AB = tiny.processingSystem() + AB.nocache = true + AB.filter = tiny.requireAll('a', 'b') + AB.process = function(_, e) + e.b = nil + tiny.addEntity(w, e) + end + AB.postProcess = function(_) tiny.refresh(w) end + + tiny.addSystem(w, A) + tiny.addSystem(w, AB) + + tiny.refresh(w) + return w +end)