mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2026-01-06 03:21:18 +07:00
proof of concept multi_clone/spawn optimizations
This commit is contained in:
@@ -5,6 +5,9 @@ require 'develop.testing.name_tests'
|
||||
require 'develop.testing.requires_fragment_tests'
|
||||
require 'develop.testing.system_as_query_tests'
|
||||
|
||||
require 'develop.benchmarks.multi_clone_bmarks'
|
||||
require 'develop.benchmarks.multi_spawn_bmarks'
|
||||
|
||||
require 'develop.untests'
|
||||
|
||||
require 'develop.unbench'
|
||||
|
||||
57
develop/benchmarks/multi_clone_bmarks.lua
Normal file
57
develop/benchmarks/multi_clone_bmarks.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
local evo = require 'evolved'
|
||||
local basics = require 'develop.basics'
|
||||
|
||||
local N = 1000
|
||||
|
||||
local F1, F2, F3, F4, F5 = evo.id(5)
|
||||
local Q1 = evo.builder():include(F1):spawn()
|
||||
|
||||
print '----------------------------------------'
|
||||
|
||||
basics.describe_bench(string.format('Multi Clone Benchmarks: Simple Clone | %d entities with 1 component', N),
|
||||
function()
|
||||
local clone = evo.clone
|
||||
|
||||
local prefab = evo.spawn { [F1] = true }
|
||||
|
||||
for _ = 1, N do
|
||||
clone(prefab)
|
||||
end
|
||||
|
||||
evo.batch_destroy(Q1)
|
||||
end)
|
||||
|
||||
basics.describe_bench(string.format('Multi Clone Benchmarks: Simple Clone | %d entities with 5 components', N),
|
||||
function()
|
||||
local clone = evo.clone
|
||||
|
||||
local prefab = evo.spawn { [F1] = true, [F2] = true, [F3] = true, [F4] = true, [F5] = true }
|
||||
|
||||
for _ = 1, N do
|
||||
clone(prefab)
|
||||
end
|
||||
|
||||
evo.batch_destroy(Q1)
|
||||
end)
|
||||
|
||||
basics.describe_bench(string.format('Multi Clone Benchmarks: Multi Clone | %d entities with 1 component', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
|
||||
local prefab = evo.spawn { [F1] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
|
||||
evo.batch_destroy(Q1)
|
||||
end)
|
||||
|
||||
basics.describe_bench(string.format('Multi Clone Benchmarks: Multi Clone | %d entities with 5 components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
|
||||
local prefab = evo.spawn { [F1] = true, [F2] = true, [F3] = true, [F4] = true, [F5] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
|
||||
evo.batch_destroy(Q1)
|
||||
end)
|
||||
57
develop/benchmarks/multi_spawn_bmarks.lua
Normal file
57
develop/benchmarks/multi_spawn_bmarks.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
local evo = require 'evolved'
|
||||
local basics = require 'develop.basics'
|
||||
|
||||
local N = 1000
|
||||
|
||||
local F1, F2, F3, F4, F5 = evo.id(5)
|
||||
local Q1 = evo.builder():include(F1):spawn()
|
||||
|
||||
print '----------------------------------------'
|
||||
|
||||
basics.describe_bench(string.format('Multi Spawn Benchmarks: Simple Spawn | %d entities with 1 component', N),
|
||||
function()
|
||||
local spawn = evo.spawn
|
||||
|
||||
local components = { [F1] = true }
|
||||
|
||||
for _ = 1, N do
|
||||
spawn(components)
|
||||
end
|
||||
|
||||
evo.batch_destroy(Q1)
|
||||
end)
|
||||
|
||||
basics.describe_bench(string.format('Multi Spawn Benchmarks: Simple Spawn | %d entities with 5 components', N),
|
||||
function()
|
||||
local spawn = evo.spawn
|
||||
|
||||
local components = { [F1] = true, [F2] = true, [F3] = true, [F4] = true, [F5] = true }
|
||||
|
||||
for _ = 1, N do
|
||||
spawn(components)
|
||||
end
|
||||
|
||||
evo.batch_destroy(Q1)
|
||||
end)
|
||||
|
||||
basics.describe_bench(string.format('Multi Spawn Benchmarks: Multi Spawn | %d entities with 1 component', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
|
||||
local components = { [F1] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
|
||||
evo.batch_destroy(Q1)
|
||||
end)
|
||||
|
||||
basics.describe_bench(string.format('Multi Spawn Benchmarks: Multi Spawn | %d entities with 5 components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
|
||||
local components = { [F1] = true, [F2] = true, [F3] = true, [F4] = true, [F5] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
|
||||
evo.batch_destroy(Q1)
|
||||
end)
|
||||
@@ -192,3 +192,117 @@ do
|
||||
assert(entity_list[2] and evo.get(entity_list[2], f1) == false and evo.get(entity_list[2], f2) == 456)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2, f3 = evo.id(3)
|
||||
|
||||
do
|
||||
local entity_list1, entity_list2
|
||||
|
||||
evo.defer()
|
||||
do
|
||||
entity_list1 = evo.multi_spawn(2, { [f1] = 42, [f2] = "hello", [f3] = false })
|
||||
assert(entity_list1 and #entity_list1 == 2)
|
||||
assert(entity_list1[1] and evo.empty(entity_list1[1]))
|
||||
assert(entity_list1[2] and evo.empty(entity_list1[2]))
|
||||
assert(not entity_list1[3])
|
||||
|
||||
entity_list2 = evo.multi_spawn(3, { [f2] = "world", [f3] = true })
|
||||
assert(entity_list2 and #entity_list2 == 3)
|
||||
assert(entity_list2[1] and evo.empty(entity_list2[1]))
|
||||
assert(entity_list2[2] and evo.empty(entity_list2[2]))
|
||||
assert(entity_list2[3] and evo.empty(entity_list2[3]))
|
||||
end
|
||||
evo.commit()
|
||||
do
|
||||
assert(entity_list1 and #entity_list1 == 2)
|
||||
assert(entity_list1[1] and not evo.empty(entity_list1[1]))
|
||||
assert(entity_list1[2] and not evo.empty(entity_list1[2]))
|
||||
assert(not entity_list1[3])
|
||||
assert(
|
||||
evo.get(entity_list1[1], f1) == 42 and
|
||||
evo.get(entity_list1[1], f2) == "hello" and
|
||||
evo.get(entity_list1[1], f3) == false)
|
||||
assert(
|
||||
evo.get(entity_list1[2], f1) == 42 and
|
||||
evo.get(entity_list1[2], f2) == "hello" and
|
||||
evo.get(entity_list1[2], f3) == false)
|
||||
|
||||
assert(entity_list2 and #entity_list2 == 3)
|
||||
assert(entity_list2[1] and not evo.empty(entity_list2[1]))
|
||||
assert(entity_list2[2] and not evo.empty(entity_list2[2]))
|
||||
assert(entity_list2[3] and not evo.empty(entity_list2[3]))
|
||||
assert(not entity_list2[4])
|
||||
assert(
|
||||
evo.get(entity_list2[1], f1) == nil and
|
||||
evo.get(entity_list2[1], f2) == "world" and
|
||||
evo.get(entity_list2[1], f3) == true)
|
||||
assert(
|
||||
evo.get(entity_list2[2], f1) == nil and
|
||||
evo.get(entity_list2[2], f2) == "world" and
|
||||
evo.get(entity_list2[2], f3) == true)
|
||||
assert(
|
||||
evo.get(entity_list2[3], f1) == nil and
|
||||
evo.get(entity_list2[3], f2) == "world" and
|
||||
evo.get(entity_list2[3], f3) == true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2, f3 = evo.id(3)
|
||||
|
||||
do
|
||||
local prefab = evo.builder():set(f1, false):set(f2, 123):spawn()
|
||||
|
||||
local entity_list1, entity_list2
|
||||
|
||||
evo.defer()
|
||||
do
|
||||
entity_list1 = evo.multi_clone(2, prefab)
|
||||
assert(entity_list1 and #entity_list1 == 2)
|
||||
assert(entity_list1[1] and evo.empty(entity_list1[1]))
|
||||
assert(entity_list1[2] and evo.empty(entity_list1[2]))
|
||||
assert(not entity_list1[3])
|
||||
|
||||
entity_list2 = evo.multi_clone(3, prefab, { [f2] = 456, [f3] = "world" })
|
||||
assert(entity_list2 and #entity_list2 == 3)
|
||||
assert(entity_list2[1] and evo.empty(entity_list2[1]))
|
||||
assert(entity_list2[2] and evo.empty(entity_list2[2]))
|
||||
assert(entity_list2[3] and evo.empty(entity_list2[3]))
|
||||
end
|
||||
evo.commit()
|
||||
do
|
||||
assert(entity_list1 and #entity_list1 == 2)
|
||||
assert(entity_list1[1] and not evo.empty(entity_list1[1]))
|
||||
assert(entity_list1[2] and not evo.empty(entity_list1[2]))
|
||||
assert(not entity_list1[3])
|
||||
assert(
|
||||
evo.get(entity_list1[1], f1) == false and
|
||||
evo.get(entity_list1[1], f2) == 123 and
|
||||
evo.get(entity_list1[1], f3) == nil)
|
||||
assert(
|
||||
evo.get(entity_list1[2], f1) == false and
|
||||
evo.get(entity_list1[2], f2) == 123 and
|
||||
evo.get(entity_list1[2], f3) == nil)
|
||||
|
||||
assert(entity_list2 and #entity_list2 == 3)
|
||||
assert(entity_list2[1] and not evo.empty(entity_list2[1]))
|
||||
assert(entity_list2[2] and not evo.empty(entity_list2[2]))
|
||||
assert(entity_list2[3] and not evo.empty(entity_list2[3]))
|
||||
assert(not entity_list2[4])
|
||||
assert(
|
||||
evo.get(entity_list2[1], f1) == false and
|
||||
evo.get(entity_list2[1], f2) == 456 and
|
||||
evo.get(entity_list2[1], f3) == "world")
|
||||
assert(
|
||||
evo.get(entity_list2[2], f1) == false and
|
||||
evo.get(entity_list2[2], f2) == 456 and
|
||||
evo.get(entity_list2[2], f3) == "world")
|
||||
assert(
|
||||
evo.get(entity_list2[3], f1) == false and
|
||||
evo.get(entity_list2[3], f2) == 456 and
|
||||
evo.get(entity_list2[3], f3) == "world")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user