mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
This commit is contained in:
parent
d77fe0f92f
commit
bbe634f433
2 changed files with 231 additions and 266 deletions
|
|
@ -114,6 +114,8 @@ local function destroy<T>(node: Node<T>)
|
||||||
while node[1] do destroy(node[1]) end
|
while node[1] do destroy(node[1]) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local update_queue = {} :: { Node<any> }
|
||||||
|
|
||||||
local function evaluate_node<T>(node: Node<T>)
|
local function evaluate_node<T>(node: Node<T>)
|
||||||
local cur_value = node.cache
|
local cur_value = node.cache
|
||||||
|
|
||||||
|
|
@ -136,6 +138,7 @@ local function evaluate_node<T>(node: Node<T>)
|
||||||
close_scope()
|
close_scope()
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
|
table.clear(update_queue)
|
||||||
throw(`side-effect error from source update\n{new_value}`)
|
throw(`side-effect error from source update\n{new_value}`)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -144,19 +147,11 @@ local function evaluate_node<T>(node: Node<T>)
|
||||||
return cur_value ~= new_value -- node has changed value
|
return cur_value ~= new_value -- node has changed value
|
||||||
end
|
end
|
||||||
|
|
||||||
local update_queue = {} :: { Node<any> }
|
local function update_from<T>(node: StartNode<T>, n0: number)
|
||||||
|
|
||||||
local function update<T>(node: StartNode<T>)
|
|
||||||
if not node[1] then return end
|
if not node[1] then return end
|
||||||
|
|
||||||
local n0 = #update_queue
|
|
||||||
local first_update = n0 == 0
|
|
||||||
local n = n0
|
local n = n0
|
||||||
|
|
||||||
if first_update then
|
|
||||||
table.clear(update_queue)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- unparent all children and queue for eval
|
-- unparent all children and queue for eval
|
||||||
do
|
do
|
||||||
local child = node[1]
|
local child = node[1]
|
||||||
|
|
@ -176,15 +171,17 @@ local function update<T>(node: StartNode<T>)
|
||||||
if not child.effect then continue end
|
if not child.effect then continue end
|
||||||
|
|
||||||
if evaluate_node(child) then
|
if evaluate_node(child) then
|
||||||
update(child)
|
update_from(child, n)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if first_update then
|
update_queue[i] = false :: any -- false instead of nil to avoid sparse
|
||||||
table.clear(update_queue)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function update<T>(node: StartNode<T>)
|
||||||
|
update_from(node, 0)
|
||||||
|
end
|
||||||
|
|
||||||
local function track<T>(node: StartNode<T>)
|
local function track<T>(node: StartNode<T>)
|
||||||
local scope = get_scope()
|
local scope = get_scope()
|
||||||
if scope and scope.effect then -- do not track nodes with no effect
|
if scope and scope.effect then -- do not track nodes with no effect
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
local BENCH, START = require("test/testkit").benchmark()
|
local testkit = require("test/testkit")
|
||||||
|
local BENCH, START = testkit.benchmark()
|
||||||
|
|
||||||
local vide = require "src/init"
|
local vide = require "src/init"
|
||||||
local root = vide.root
|
|
||||||
local source = vide.source
|
local source = vide.source
|
||||||
local derive = vide.derive
|
local derive = vide.derive
|
||||||
local indexes = vide.indexes
|
local indexes = vide.indexes
|
||||||
|
|
@ -9,11 +9,23 @@ local values = vide.values
|
||||||
local cleanup = vide.cleanup
|
local cleanup = vide.cleanup
|
||||||
local create = vide.create
|
local create = vide.create
|
||||||
|
|
||||||
|
local function TITLE(name: string)
|
||||||
|
print()
|
||||||
|
print(testkit.color.white(name))
|
||||||
|
end
|
||||||
|
|
||||||
local N = 2^18 -- 262144
|
local N = 2^18 -- 262144
|
||||||
|
|
||||||
-- todo: wide and deep graph benchmarks
|
local function WRAP_BENCH(name: string, fn: () -> ())
|
||||||
|
local _, destroy = vide.root(function()
|
||||||
|
BENCH(name, fn)
|
||||||
|
end)
|
||||||
|
destroy()
|
||||||
|
end
|
||||||
|
|
||||||
BENCH("create source", function()
|
TITLE "sources"
|
||||||
|
|
||||||
|
WRAP_BENCH("create source", function()
|
||||||
local cache = table.create(N)
|
local cache = table.create(N)
|
||||||
|
|
||||||
for i = 1, START(N) do
|
for i = 1, START(N) do
|
||||||
|
|
@ -21,7 +33,7 @@ BENCH("create source", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("get value", function()
|
WRAP_BENCH("get value", function()
|
||||||
local src = source(1)
|
local src = source(1)
|
||||||
|
|
||||||
for i = 1, START(N) do
|
for i = 1, START(N) do
|
||||||
|
|
@ -29,7 +41,7 @@ BENCH("get value", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("set value", function()
|
WRAP_BENCH("set value", function()
|
||||||
local src = source(1)
|
local src = source(1)
|
||||||
|
|
||||||
for i = 1, START(N) do
|
for i = 1, START(N) do
|
||||||
|
|
@ -37,148 +49,129 @@ BENCH("set value", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("derive 1 source", function()
|
WRAP_BENCH("derive 1 source", function()
|
||||||
local cache = table.create(N)
|
local cache = table.create(N)
|
||||||
local src = source(1)
|
local src = source(1)
|
||||||
|
|
||||||
root(function()
|
for i = 1, START(N) do
|
||||||
for i = 1, START(N) do
|
cache[i] = derive(function()
|
||||||
cache[i] = derive(function()
|
return src()
|
||||||
return src()
|
end)
|
||||||
end)
|
end
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("derive 4 sources", function()
|
WRAP_BENCH("derive 4 sources", function()
|
||||||
local cache = table.create(N)
|
local cache = table.create(N)
|
||||||
local src = vide.source(1)
|
local src = vide.source(1)
|
||||||
local src2 = vide.source(2)
|
local src2 = vide.source(2)
|
||||||
local src3 = vide.source(3)
|
local src3 = vide.source(3)
|
||||||
local src4 = vide.source(4)
|
local src4 = vide.source(4)
|
||||||
|
|
||||||
vide.root(function()
|
for i = 1, START(N) do
|
||||||
for i = 1, START(N) do
|
cache[i] = derive(function()
|
||||||
cache[i] = derive(function()
|
return src() + src2() + src3() + src4()
|
||||||
return src() + src2() + src3() + src4()
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
BENCH("update 1->1 graph", function()
|
|
||||||
local src = source(1)
|
|
||||||
|
|
||||||
root(function()
|
|
||||||
local _derived = derive(function() return src() end)
|
|
||||||
|
|
||||||
for i = 1, START(N) do
|
|
||||||
src(i)
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
BENCH("update 1->1 graph with cleanup", function()
|
|
||||||
local src = source(1)
|
|
||||||
|
|
||||||
root(function()
|
|
||||||
derive(function()
|
|
||||||
cleanup(function() end)
|
|
||||||
return src()
|
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
for i = 1, START(N) do
|
|
||||||
src(i)
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("update 1->1000 graph", function()
|
TITLE "graphs"
|
||||||
local src = source(-1)
|
|
||||||
|
|
||||||
root(function()
|
WRAP_BENCH("update 1->1 graph", function()
|
||||||
for i = 1, 1000 do
|
local src = source(1)
|
||||||
derive(function() return src() end)
|
|
||||||
end
|
|
||||||
|
|
||||||
src(0)
|
local _derived = derive(function() return src() end)
|
||||||
|
|
||||||
for i = 1, START(10) do
|
for i = 1, START(N) do
|
||||||
src(i)
|
src(i)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("update 1->1->1->1...1000 graph", function()
|
WRAP_BENCH("update 1->1 graph with cleanup", function()
|
||||||
|
local src = source(1)
|
||||||
|
|
||||||
|
derive(function()
|
||||||
|
cleanup(function() end)
|
||||||
|
return src()
|
||||||
|
end)
|
||||||
|
|
||||||
|
for i = 1, START(N) do
|
||||||
|
src(i)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
WRAP_BENCH("update 1->1000 graph", function()
|
||||||
local src = source(-1)
|
local src = source(-1)
|
||||||
|
|
||||||
root(function()
|
for i = 1, 1000 do
|
||||||
local last = src
|
derive(function() return src() end)
|
||||||
for i = 1, 1000 do
|
end
|
||||||
local l = last
|
|
||||||
last = derive(function() return l() end)
|
|
||||||
end
|
|
||||||
|
|
||||||
src(0)
|
src(0)
|
||||||
|
|
||||||
for i = 1, START(10) do
|
for i = 1, START(10) do
|
||||||
src(i)
|
src(i)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
WRAP_BENCH("update 1->1->1->1...1000 graph", function()
|
||||||
|
local src = source(-1)
|
||||||
|
|
||||||
|
local last = src
|
||||||
|
for i = 1, 1000 do
|
||||||
|
local l = last
|
||||||
|
last = derive(function() return l() end)
|
||||||
|
end
|
||||||
|
|
||||||
|
src(0)
|
||||||
|
|
||||||
|
for i = 1, START(10) do
|
||||||
|
src(i)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- todo: repeat with batching
|
-- todo: repeat with batching
|
||||||
BENCH("update 1000->1 graph", function()
|
WRAP_BENCH("update 1000->1 graph", function()
|
||||||
local srcs = {}
|
local srcs = {}
|
||||||
for i = 1, 1000 do
|
for i = 1, 1000 do
|
||||||
srcs[i] = source(0)
|
srcs[i] = source(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
root(function()
|
derive(function()
|
||||||
derive(function()
|
for i = 1, 1000 do
|
||||||
for i = 1, 1000 do
|
srcs[i]()
|
||||||
srcs[i]()
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end)
|
|
||||||
|
|
||||||
for i = 1, START(1) do
|
|
||||||
for idx = 1, 1000 do
|
|
||||||
srcs[idx](i)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
for i = 1, START(1) do
|
||||||
|
for idx = 1, 1000 do
|
||||||
|
srcs[idx](i)
|
||||||
|
end
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- todo: optimize, repeat with batching
|
-- todo: optimize, repeat with batching
|
||||||
BENCH("update 1000x 1->1 common extern. graph", function()
|
WRAP_BENCH("update 1000x 1->1 common extern. graph", function()
|
||||||
local ext = source(-1)
|
local ext = source(-1)
|
||||||
|
|
||||||
root(function()
|
local srcs = {}
|
||||||
local srcs = {}
|
for i = 1, 1000 do
|
||||||
for i = 1, 1000 do
|
srcs[i] = source(0)
|
||||||
srcs[i] = source(0)
|
derive(function() return srcs[i]() + ext() end)
|
||||||
derive(function() return srcs[i]() + ext() end)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
ext(0)
|
ext(0)
|
||||||
|
|
||||||
for i = 1, START(10) do
|
for i = 1, START(10) do
|
||||||
for idx = 1, 1000 do
|
for idx = 1, 1000 do
|
||||||
srcs[idx](i)
|
srcs[idx](i)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("apply 0 properties", function()
|
TITLE "property apply"
|
||||||
|
|
||||||
|
WRAP_BENCH("apply 0 properties", function()
|
||||||
local apply = require "src/apply"
|
local apply = require "src/apply"
|
||||||
local instance = create("Frame") {}
|
local instance = create("Frame") {}
|
||||||
|
|
||||||
|
|
@ -187,7 +180,7 @@ BENCH("apply 0 properties", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("apply 8 properties", function()
|
WRAP_BENCH("apply 8 properties", function()
|
||||||
local apply = require "src/apply"
|
local apply = require "src/apply"
|
||||||
local instance = create("Frame") {}
|
local instance = create("Frame") {}
|
||||||
|
|
||||||
|
|
@ -205,45 +198,43 @@ BENCH("apply 8 properties", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("bind property", function()
|
WRAP_BENCH("bind property", function()
|
||||||
local apply = require "src/apply"
|
local apply = require "src/apply"
|
||||||
|
|
||||||
local instance = create("Frame") {}
|
local instance = create("Frame") {}
|
||||||
local src = source(1)
|
local src = source(1)
|
||||||
|
|
||||||
root(function()
|
for i = 1, START(N) do
|
||||||
for i = 1, START(N) do
|
|
||||||
apply(instance, {
|
|
||||||
Text = src
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
BENCH("update binding", function()
|
|
||||||
local apply = require "src/apply"
|
|
||||||
|
|
||||||
local instance = create("Frame") {}
|
|
||||||
local src = source(1)
|
|
||||||
|
|
||||||
root(function()
|
|
||||||
apply(instance, {
|
apply(instance, {
|
||||||
Text = src
|
Text = src
|
||||||
})
|
})
|
||||||
|
end
|
||||||
|
|
||||||
for i = 1, START(N) do
|
return nil
|
||||||
src(i)
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
WRAP_BENCH("update binding", function()
|
||||||
|
local apply = require "src/apply"
|
||||||
|
|
||||||
|
local instance = create("Frame") {}
|
||||||
|
local src = source(1)
|
||||||
|
|
||||||
|
apply(instance, {
|
||||||
|
Text = src
|
||||||
|
})
|
||||||
|
|
||||||
|
for i = 1, START(N) do
|
||||||
|
src(i)
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
TITLE "indexes()"
|
||||||
|
|
||||||
N /= 1024
|
N /= 1024
|
||||||
|
|
||||||
BENCH("indexes() all new", function()
|
WRAP_BENCH("indexes() all new", function()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
|
|
@ -252,18 +243,16 @@ BENCH("indexes() all new", function()
|
||||||
|
|
||||||
local src = source(data)
|
local src = source(data)
|
||||||
|
|
||||||
root(function()
|
START(N)
|
||||||
START(N)
|
|
||||||
|
|
||||||
local _list = indexes(src, function(v, i)
|
local _list = indexes(src, function(v, i)
|
||||||
return {}
|
return {}
|
||||||
end)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
return nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("indexes() no change", function()
|
WRAP_BENCH("indexes() no change", function()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
|
|
@ -272,20 +261,18 @@ BENCH("indexes() no change", function()
|
||||||
|
|
||||||
local src = source(data)
|
local src = source(data)
|
||||||
|
|
||||||
root(function()
|
local _list = indexes(src, function(v, i)
|
||||||
local _list = indexes(src, function(v, i)
|
return {}
|
||||||
return {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
START(N)
|
|
||||||
|
|
||||||
src(data)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
START(N)
|
||||||
|
|
||||||
|
src(data)
|
||||||
|
|
||||||
|
return nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("indexes() all change", function()
|
WRAP_BENCH("indexes() all change", function()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
|
|
@ -294,27 +281,22 @@ BENCH("indexes() all change", function()
|
||||||
|
|
||||||
local src = source(data)
|
local src = source(data)
|
||||||
|
|
||||||
|
local _list = indexes(src, function(v, i)
|
||||||
root(function()
|
return {}
|
||||||
local _list = indexes(src, function(v, i)
|
|
||||||
return {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
--src(src()) -- fill double buffer
|
|
||||||
|
|
||||||
for i, v in data do
|
|
||||||
data[i] = v + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
START(N)
|
|
||||||
|
|
||||||
src(data)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--src(src()) -- fill double buffer
|
||||||
|
|
||||||
|
for i, v in data do
|
||||||
|
data[i] = v + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
START(N)
|
||||||
|
|
||||||
|
src(data)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("indexes() all remove", function()
|
WRAP_BENCH("indexes() all remove", function()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
|
|
@ -323,22 +305,22 @@ BENCH("indexes() all remove", function()
|
||||||
|
|
||||||
local src = source(data)
|
local src = source(data)
|
||||||
|
|
||||||
root(function()
|
local _list = indexes(src, function(v, i)
|
||||||
local _list = indexes(src, function(v, i)
|
return {}
|
||||||
return {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
table.clear(data)
|
|
||||||
|
|
||||||
START(N)
|
|
||||||
|
|
||||||
src(data)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
table.clear(data)
|
||||||
|
|
||||||
|
START(N)
|
||||||
|
|
||||||
|
src(data)
|
||||||
|
|
||||||
|
return nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("values() all new", function()
|
TITLE "values()"
|
||||||
|
|
||||||
|
WRAP_BENCH("values() all new", function()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
|
|
@ -347,18 +329,16 @@ BENCH("values() all new", function()
|
||||||
|
|
||||||
local src = source(data)
|
local src = source(data)
|
||||||
|
|
||||||
root(function()
|
START(N)
|
||||||
START(N)
|
|
||||||
|
local _list = values(src, function(v, i)
|
||||||
local _list = values(src, function(v, i)
|
return {}
|
||||||
return {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
return nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("values() no change", function()
|
WRAP_BENCH("values() no change", function()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
|
|
@ -367,22 +347,18 @@ BENCH("values() no change", function()
|
||||||
|
|
||||||
local src = source(data)
|
local src = source(data)
|
||||||
|
|
||||||
root(function()
|
local _list = values(src, function(v, i)
|
||||||
local _list = values(src, function(v, i)
|
return {}
|
||||||
return {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
src(src()) -- fill double buffer
|
|
||||||
|
|
||||||
START(N)
|
|
||||||
|
|
||||||
src(data)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
src(src()) -- fill double buffer
|
||||||
|
|
||||||
|
START(N)
|
||||||
|
|
||||||
|
src(data)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("values() all change", function()
|
WRAP_BENCH("values() all change", function()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
|
|
@ -391,27 +367,23 @@ BENCH("values() all change", function()
|
||||||
|
|
||||||
local src = source(data)
|
local src = source(data)
|
||||||
|
|
||||||
root(function()
|
local _list = values(src, function(v, i)
|
||||||
local _list = values(src, function(v, i)
|
return {}
|
||||||
return {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
src(src()) -- fill double buffer
|
|
||||||
|
|
||||||
for i = 1, N do
|
|
||||||
local r = math.random(1, #data)
|
|
||||||
data[i], data[r] = data[r], data[i]
|
|
||||||
end
|
|
||||||
|
|
||||||
START(N)
|
|
||||||
|
|
||||||
src(data)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
src(src()) -- fill double buffer
|
||||||
|
|
||||||
|
for i = 1, N do
|
||||||
|
local r = math.random(1, #data)
|
||||||
|
data[i], data[r] = data[r], data[i]
|
||||||
|
end
|
||||||
|
|
||||||
|
START(N)
|
||||||
|
|
||||||
|
src(data)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("values() all remove", function()
|
WRAP_BENCH("values() all remove", function()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
|
|
@ -420,50 +392,46 @@ BENCH("values() all remove", function()
|
||||||
|
|
||||||
local src = source(data)
|
local src = source(data)
|
||||||
|
|
||||||
root(function()
|
local _list = values(src, function(v, i)
|
||||||
local _list = values(src, function(v, i)
|
return {}
|
||||||
return {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
table.clear(data)
|
|
||||||
|
|
||||||
START(N)
|
|
||||||
|
|
||||||
src(data)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
table.clear(data)
|
||||||
|
|
||||||
|
START(N)
|
||||||
|
|
||||||
|
src(data)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
N *= 1024
|
N *= 1024
|
||||||
|
|
||||||
BENCH("register new cleanup", function()
|
TITLE "cleanup"
|
||||||
|
|
||||||
|
WRAP_BENCH("register new cleanup", function()
|
||||||
local cleanup = cleanup
|
local cleanup = cleanup
|
||||||
|
|
||||||
root(function()
|
local cleaner = function() end
|
||||||
local cleaner = function() end
|
|
||||||
|
|
||||||
local callers = {}
|
local callers = {}
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
callers[i] = function(fn, v)
|
callers[i] = function(fn, v)
|
||||||
fn(v)
|
fn(v)
|
||||||
return i -- return unique upvalue to ensure unique closure
|
return i -- return unique upvalue to ensure unique closure
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for i = 1, START(N) do
|
for i = 1, START(N) do
|
||||||
callers[i](cleanup, cleaner)
|
callers[i](cleanup, cleaner)
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
TITLE "aggregate"
|
||||||
|
|
||||||
do
|
do
|
||||||
-- the purpose of the two following benchmarks is to measure the overhead of
|
-- the purpose of the two following benchmarks is to measure the overhead of
|
||||||
-- aggregate construction
|
-- aggregate construction
|
||||||
BENCH("set explicit mock vector2", function()
|
WRAP_BENCH("set explicit mock vector2", function()
|
||||||
local apply = require "src/apply"
|
local apply = require "src/apply"
|
||||||
local Vector2 = require "test/mock".Vector2
|
local Vector2 = require "test/mock".Vector2
|
||||||
|
|
||||||
|
|
@ -478,7 +446,7 @@ do
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
BENCH("set aggregate mock vector2", function()
|
WRAP_BENCH("set aggregate mock vector2", function()
|
||||||
local apply = require "src/apply"
|
local apply = require "src/apply"
|
||||||
local Vector2 = require "test/mock".Vector2
|
local Vector2 = require "test/mock".Vector2
|
||||||
|
|
||||||
|
|
@ -497,7 +465,7 @@ end
|
||||||
-- innacurate due to no Vector3 in vanilla Luau
|
-- innacurate due to no Vector3 in vanilla Luau
|
||||||
-- mock vector is 200x slower than native vector
|
-- mock vector is 200x slower than native vector
|
||||||
|
|
||||||
-- BENCH("spring update", function()
|
-- WRAP_BENCH("spring update", function()
|
||||||
-- local root, source, spring = vide.root, vide.source, vide.spring
|
-- local root, source, spring = vide.root, vide.source, vide.spring
|
||||||
|
|
||||||
-- local src = source(0)
|
-- local src = source(0)
|
||||||
|
|
@ -517,7 +485,7 @@ end
|
||||||
|
|
||||||
-- N /= 1024
|
-- N /= 1024
|
||||||
|
|
||||||
-- BENCH("spring step", function()
|
-- WRAP_BENCH("spring step", function()
|
||||||
-- local root, source, spring = vide.root, vide.source, vide.spring
|
-- local root, source, spring = vide.root, vide.source, vide.spring
|
||||||
|
|
||||||
-- local src = source(0)
|
-- local src = source(0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue