2024-05-01 12:41:51 +00:00
|
|
|
--!optimize 2
|
|
|
|
|
--!native
|
|
|
|
|
|
2025-11-30 02:47:51 +00:00
|
|
|
local testkit = require("@modules/testkit")
|
2024-05-01 12:41:51 +00:00
|
|
|
local BENCH, START = testkit.benchmark()
|
|
|
|
|
local function TITLE(title: string)
|
2024-05-04 23:52:01 +00:00
|
|
|
print()
|
|
|
|
|
print(testkit.color.white(title))
|
2024-05-01 12:41:51 +00:00
|
|
|
end
|
2024-07-07 02:53:17 +00:00
|
|
|
|
2024-07-06 21:37:11 +00:00
|
|
|
local jecs = require("@jecs")
|
2025-01-14 10:09:18 +00:00
|
|
|
local mirror = require("@mirror")
|
2024-05-01 12:41:51 +00:00
|
|
|
|
2024-05-04 23:52:01 +00:00
|
|
|
do
|
|
|
|
|
TITLE(testkit.color.white_underline("Jecs query"))
|
2025-08-28 15:10:23 +00:00
|
|
|
local ecs = jecs.world() :: jecs.World
|
2024-05-04 23:52:01 +00:00
|
|
|
do
|
|
|
|
|
TITLE("one component in common")
|
|
|
|
|
|
2025-08-28 15:10:23 +00:00
|
|
|
local function view_bench(world: jecs.World,
|
|
|
|
|
A: jecs.Id,
|
|
|
|
|
B: jecs.Id,
|
|
|
|
|
C: jecs.Id,
|
|
|
|
|
D: jecs.Id,
|
|
|
|
|
E: jecs.Id,
|
|
|
|
|
F: jecs.Id,
|
|
|
|
|
G: jecs.Id,
|
|
|
|
|
H: jecs.Id
|
|
|
|
|
)
|
2024-05-04 23:52:01 +00:00
|
|
|
BENCH("4 component", function()
|
2024-07-14 04:35:13 +00:00
|
|
|
for _ in world:query(D, C, B, A) do
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local D1 = ecs:component()
|
|
|
|
|
local D2 = ecs:component()
|
|
|
|
|
local D3 = ecs:component()
|
|
|
|
|
local D4 = ecs:component()
|
|
|
|
|
local D5 = ecs:component()
|
|
|
|
|
local D6 = ecs:component()
|
|
|
|
|
local D7 = ecs:component()
|
|
|
|
|
local D8 = ecs:component()
|
|
|
|
|
|
2024-05-05 13:06:57 +00:00
|
|
|
local function flip()
|
|
|
|
|
return math.random() >= 0.15
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local added = 0
|
|
|
|
|
local archetypes = {}
|
2025-12-28 10:07:51 +00:00
|
|
|
for i = 1, 2 ^ 12 - 2 do
|
2024-05-05 13:06:57 +00:00
|
|
|
local entity = ecs:entity()
|
2025-12-28 10:07:51 +00:00
|
|
|
ecs:add(entity, entity)
|
2024-05-05 13:06:57 +00:00
|
|
|
|
|
|
|
|
local combination = ""
|
|
|
|
|
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "B"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D2, { value = true })
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "C"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D3, { value = true })
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "D"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D4, { value = true })
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "E"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D5, { value = true })
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "F"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D6, { value = true })
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "G"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D7, { value = true })
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "H"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D8, { value = true })
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if #combination == 7 then
|
|
|
|
|
added += 1
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D1, { value = true })
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
archetypes[combination] = true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local a = 0
|
|
|
|
|
for _ in archetypes do
|
|
|
|
|
a += 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
view_bench(ecs, D1, D2, D3, D4, D5, D6, D7, D8)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
TITLE(testkit.color.white_underline("Mirror query"))
|
2025-08-28 15:10:23 +00:00
|
|
|
local ecs = mirror.World.new() :: jecs.World
|
2024-05-05 13:06:57 +00:00
|
|
|
do
|
|
|
|
|
TITLE("one component in common")
|
|
|
|
|
|
2025-08-28 15:10:23 +00:00
|
|
|
local function view_bench(
|
|
|
|
|
world: mirror.World,
|
|
|
|
|
A: jecs.Id,
|
|
|
|
|
B: jecs.Id,
|
|
|
|
|
C: jecs.Id,
|
|
|
|
|
D: jecs.Id,
|
|
|
|
|
E: jecs.Id,
|
|
|
|
|
F: jecs.Id,
|
|
|
|
|
G: jecs.Id,
|
|
|
|
|
H: jecs.Id
|
|
|
|
|
)
|
2024-05-05 13:06:57 +00:00
|
|
|
BENCH("4 component", function()
|
2024-07-14 04:35:13 +00:00
|
|
|
for _ in world:query(D, C, B, A) do
|
2024-05-05 13:06:57 +00:00
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local D1 = ecs:component()
|
|
|
|
|
local D2 = ecs:component()
|
|
|
|
|
local D3 = ecs:component()
|
|
|
|
|
local D4 = ecs:component()
|
|
|
|
|
local D5 = ecs:component()
|
|
|
|
|
local D6 = ecs:component()
|
|
|
|
|
local D7 = ecs:component()
|
|
|
|
|
local D8 = ecs:component()
|
|
|
|
|
|
2024-05-04 23:52:01 +00:00
|
|
|
local function flip()
|
2025-12-28 10:07:51 +00:00
|
|
|
return math.random() >= 0.5
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local added = 0
|
2024-05-01 12:41:51 +00:00
|
|
|
local archetypes = {}
|
2025-12-28 10:07:51 +00:00
|
|
|
for i = 1, 2 ^ 12 - 2 do
|
2024-05-04 23:52:01 +00:00
|
|
|
local entity = ecs:entity()
|
2025-12-28 10:07:51 +00:00
|
|
|
ecs:add(entity, entity)
|
2024-05-04 23:52:01 +00:00
|
|
|
|
|
|
|
|
local combination = ""
|
|
|
|
|
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "B"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D2, { value = true })
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "C"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D3, { value = true })
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "D"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D4, { value = true })
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "E"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D5, { value = true })
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "F"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D6, { value = true })
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "G"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D7, { value = true })
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
if flip() then
|
|
|
|
|
combination ..= "H"
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D8, { value = true })
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
|
2025-12-28 10:07:51 +00:00
|
|
|
if flip() then
|
2024-10-12 20:18:11 +00:00
|
|
|
ecs:set(entity, D1, { value = true })
|
2024-05-04 23:52:01 +00:00
|
|
|
end
|
|
|
|
|
end
|
2024-05-01 12:41:51 +00:00
|
|
|
|
|
|
|
|
local a = 0
|
2024-05-04 23:52:01 +00:00
|
|
|
for _ in archetypes do
|
|
|
|
|
a += 1
|
|
|
|
|
end
|
2024-05-01 12:41:51 +00:00
|
|
|
|
2024-05-04 23:52:01 +00:00
|
|
|
view_bench(ecs, D1, D2, D3, D4, D5, D6, D7, D8)
|
|
|
|
|
end
|
2024-07-06 21:30:14 +00:00
|
|
|
end
|