jecs/benches/visual/query.bench.luau

189 lines
4.2 KiB
Text
Raw Normal View History

2024-04-23 15:10:49 +00:00
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local rgb = require(ReplicatedStorage.rgb)
2024-06-21 23:08:51 +00:00
local Matter = require(ReplicatedStorage.DevPackages["_Index"]["matter-ecs_matter@0.8.1"].matter)
local ecr = require(ReplicatedStorage.DevPackages["_Index"]["centau_ecr@0.8.0"].ecr)
2024-04-23 15:10:49 +00:00
local newWorld = Matter.World.new()
2024-04-24 15:32:07 +00:00
2024-06-23 23:30:59 +00:00
local jecs = require(ReplicatedStorage.Lib)
2024-04-25 05:26:38 +00:00
local mirror = require(ReplicatedStorage.mirror)
local mcs = mirror.World.new()
2024-04-23 15:10:49 +00:00
local ecs = jecs.World.new()
local A1 = Matter.component()
local A2 = Matter.component()
local A3 = Matter.component()
local A4 = Matter.component()
local A5 = Matter.component()
local A6 = Matter.component()
local A7 = Matter.component()
local A8 = Matter.component()
local B1 = ecr.component()
local B2 = ecr.component()
local B3 = ecr.component()
local B4 = ecr.component()
local B5 = ecr.component()
local B6 = ecr.component()
local B7 = ecr.component()
local B8 = ecr.component()
2024-04-30 23:09:15 +00:00
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-04-24 15:32:07 +00:00
2024-04-23 15:10:49 +00:00
2024-04-25 05:26:38 +00:00
local E1 = mcs:entity()
local E2 = mcs:entity()
local E3 = mcs:entity()
local E4 = mcs:entity()
local E5 = mcs:entity()
local E6 = mcs:entity()
local E7 = mcs:entity()
local E8 = mcs:entity()
2024-04-23 15:10:49 +00:00
local registry2 = ecr.registry()
2024-07-15 18:29:06 +00:00
local function flip()
2024-04-25 14:26:30 +00:00
return math.random() >= 0.15
2024-04-23 15:10:49 +00:00
end
local common = 0
2024-07-28 10:33:38 +00:00
local N = 500
2024-04-23 15:10:49 +00:00
local archetypes = {}
2024-04-25 14:26:30 +00:00
local hm = 0
2024-07-15 18:29:06 +00:00
for i = 1, N do
2024-04-23 15:10:49 +00:00
local id = registry2.create()
local combination = ""
local n = newWorld:spawn()
local entity = ecs:entity()
2024-04-25 05:26:38 +00:00
local m = mcs:entity()
2024-04-23 15:10:49 +00:00
2024-07-15 18:29:06 +00:00
if flip() then
2024-04-23 15:10:49 +00:00
combination ..= "B"
2024-07-15 18:29:06 +00:00
registry2:set(id, B2, {value = true})
2024-04-24 15:32:07 +00:00
ecs:set(entity, D2, { value = true})
2024-04-25 05:26:38 +00:00
mcs:set(m, E2, { value = 2})
2024-04-24 15:32:07 +00:00
newWorld:insert(n, A2({value = true}))
2024-04-23 15:10:49 +00:00
end
2024-07-15 18:29:06 +00:00
if flip() then
2024-04-23 15:10:49 +00:00
combination ..= "C"
2024-07-15 18:29:06 +00:00
registry2:set(id, B3, {value = true})
2024-04-24 15:32:07 +00:00
ecs:set(entity, D3, { value = true})
2024-04-25 05:26:38 +00:00
mcs:set(m, E3, { value = 2})
2024-04-23 15:10:49 +00:00
newWorld:insert(n, A3({value = true}))
end
2024-07-15 18:29:06 +00:00
if flip() then
2024-04-23 15:10:49 +00:00
combination ..= "D"
2024-07-15 18:29:06 +00:00
registry2:set(id, B4, {value = true})
2024-04-24 15:32:07 +00:00
ecs:set(entity, D4, { value = true})
2024-04-25 05:26:38 +00:00
mcs:set(m, E4, { value = 2})
2024-07-15 18:29:06 +00:00
newWorld:insert(n, A4({value = true}))
2024-04-23 15:10:49 +00:00
end
2024-07-15 18:29:06 +00:00
if flip() then
2024-04-23 15:10:49 +00:00
combination ..= "E"
2024-07-15 18:29:06 +00:00
registry2:set(id, B5, {value = true})
2024-04-24 15:32:07 +00:00
ecs:set(entity, D5, { value = true})
2024-04-25 05:26:38 +00:00
mcs:set(m, E5, { value = 2})
2024-07-15 18:29:06 +00:00
newWorld:insert(n, A5({value = true}))
2024-04-23 15:10:49 +00:00
end
2024-07-15 18:29:06 +00:00
if flip() then
2024-04-23 15:10:49 +00:00
combination ..= "F"
2024-07-15 18:29:06 +00:00
registry2:set(id, B6, {value = true})
2024-04-24 15:32:07 +00:00
ecs:set(entity, D6, { value = true})
2024-04-25 05:26:38 +00:00
mcs:set(m, E6, { value = 2})
2024-07-15 18:29:06 +00:00
newWorld:insert(n, A6({value = true}))
2024-04-23 15:10:49 +00:00
end
2024-07-15 18:29:06 +00:00
if flip() then
2024-04-23 15:10:49 +00:00
combination ..= "G"
2024-07-15 18:29:06 +00:00
registry2:set(id, B7, {value = true})
2024-04-24 15:32:07 +00:00
ecs:set(entity, D7, { value = true})
2024-04-25 05:26:38 +00:00
mcs:set(m, E7, { value = 2})
2024-07-15 18:29:06 +00:00
newWorld:insert(n, A7({value = true}))
2024-04-23 15:10:49 +00:00
end
2024-07-15 18:29:06 +00:00
if flip() then
2024-04-23 15:10:49 +00:00
combination ..= "H"
2024-07-15 18:29:06 +00:00
registry2:set(id, B8, {value = true})
newWorld:insert(n, A8({value = true}))
2024-04-24 15:32:07 +00:00
ecs:set(entity, D8, { value = true})
2024-04-25 05:26:38 +00:00
mcs:set(m, E8, { value = 2})
2024-04-23 15:10:49 +00:00
end
2024-07-15 18:29:06 +00:00
if #combination == 7 then
2024-04-23 15:10:49 +00:00
combination = "A" .. combination
common += 1
2024-07-15 18:29:06 +00:00
registry2:set(id, B1, {value = true})
2024-04-24 15:32:07 +00:00
ecs:set(entity, D1, { value = true})
2024-07-15 18:29:06 +00:00
newWorld:insert(n, A1({value = true}))
2024-04-25 05:26:38 +00:00
mcs:set(m, E1, { value = 2})
2024-04-23 15:10:49 +00:00
end
2024-07-15 18:29:06 +00:00
if combination:find("BCDF") then
if not archetypes[combination] then
2024-04-25 14:26:30 +00:00
print(combination)
2024-07-15 18:29:06 +00:00
end
2024-04-25 14:26:30 +00:00
hm += 1
end
2024-04-23 15:10:49 +00:00
archetypes[combination] = true
end
2024-04-25 14:26:30 +00:00
print("TEST", hm)
2024-04-23 15:10:49 +00:00
local white = rgb.white
local yellow = rgb.yellow
local gray = rgb.gray
local green = rgb.green
local WALL = gray(" │ ")
local numberOfArchetypes = 0
2024-07-15 18:29:06 +00:00
for _ in archetypes do
2024-04-23 15:10:49 +00:00
numberOfArchetypes += 1
end
print(common)
print(
"N entities "..yellow(N)
..WALL
.."with common components: "
..yellow(tostring(common).."/"..tostring(N)).." "
..yellow("("..string.format("%.2f", (common / (2^16 - 2)* 100)).."%)")
..WALL
..yellow("Total Archetypes: "..numberOfArchetypes)
)
return {
ParameterGenerator = function()
return
2024-07-15 18:29:06 +00:00
end,
2024-04-23 15:10:49 +00:00
Functions = {
2024-07-28 10:33:38 +00:00
Mirror = function()
for i = 1, 1000 do
for entityId, firstComponent in mcs:query(E1, E4) do
end
2024-04-25 14:41:41 +00:00
end
2024-07-28 10:33:38 +00:00
2024-04-25 14:41:41 +00:00
end,
2024-07-15 18:29:06 +00:00
Jecs = function()
2024-07-28 10:33:38 +00:00
for i = 1, 1000 do
for entityId, firstComponent in ecs:query(D1, D4) do
end
2024-06-21 23:08:51 +00:00
end
2024-04-25 14:26:30 +00:00
end,
2024-04-23 15:10:49 +00:00
},
}