This commit is contained in:
aaron 2023-09-08 00:07:22 +01:00
parent 574eb8e4c5
commit 7a9d7ccc12

View file

@ -15,9 +15,10 @@ local vide = require "src/init"
local N = 2^18 -- 262144[ local N = 2^18 -- 262144[
BENCH("create state", function() BENCH("create state", function()
local cache = table.create(N)
local source = vide.source local source = vide.source
local cache = table.create(N)
for i = 1, START(N) do for i = 1, START(N) do
cache[i] = source(1) cache[i] = source(1)
end end
@ -40,39 +41,53 @@ BENCH("set value", function()
end) end)
BENCH("derive 1 state", function() BENCH("derive 1 state", function()
local cache = table.create(N)
local state = vide.source(1)
local derive = vide.derive local derive = vide.derive
for i = 1, START(N) do local cache = table.create(N)
cache[i] = derive(function() local state = vide.source(1)
return state()
end) vide.root(function()
end for i = 1, START(N) do
cache[i] = derive(function()
return state()
end)
end
return nil
end)
end) end)
BENCH("derive 4 states", function() BENCH("derive 4 states", function()
local derive = vide.derive
local cache = table.create(N) local cache = table.create(N)
local state = vide.source(1) local state = vide.source(1)
local state2 = vide.source(2) local state2 = vide.source(2)
local state3 = vide.source(3) local state3 = vide.source(3)
local state4 = vide.source(4) local state4 = vide.source(4)
local derive = vide.derive
for i = 1, START(N) do vide.root(function()
cache[i] = derive(function() for i = 1, START(N) do
return state() + state2() + state3() + state4() cache[i] = derive(function()
end) return state() + state2() + state3() + state4()
end end)
end
return nil
end)
end) end)
BENCH("set derived value", function() BENCH("set derived value", function()
local state = vide.source(1) local state = vide.source(1)
local _derived = vide.derive(state)
for i = 1, START(N) do vide.root(function()
state(i) local _derived = vide.derive(state)
end
for i = 1, START(N) do
state(i)
end
return nil
end)
end) end)
BENCH("apply 0 properties", function() BENCH("apply 0 properties", function()
@ -104,28 +119,38 @@ end)
BENCH("bind source", function() BENCH("bind source", function()
local apply = require "src/apply" local apply = require "src/apply"
local instance = vide.create("Frame") {} local instance = vide.create("Frame") {}
local state = vide.source(1) local state = vide.source(1)
for i = 1, START(N) do vide.root(function()
apply(instance, { for i = 1, START(N) do
Name = state apply(instance, {
}) Name = state
end })
end
return nil
end)
end) end)
BENCH("update binding", function() BENCH("update binding", function()
local apply = require "src/apply" local apply = require "src/apply"
local instance = vide.create("Frame") {} local instance = vide.create("Frame") {}
local state = vide.source(1) local state = vide.source(1)
apply(instance, { vide.root(function()
Name = state apply(instance, {
}) Name = state
})
for i = 1, START(N) do for i = 1, START(N) do
state(i) state(i)
end end
return nil
end)
end) end)
BENCH("indexes() no change", function() BENCH("indexes() no change", function()
@ -137,15 +162,19 @@ BENCH("indexes() no change", function()
local state = vide.source(data) local state = vide.source(data)
local _list = vide.indexes(state, function(v, i) vide.root(function()
return {} local _list = vide.indexes(state, function(v, i)
return {}
end)
--state(state()) -- fill double buffer
START(N)
state(data)
return nil
end) end)
--state(state()) -- fill double buffer
START(N)
state(data)
end) end)
BENCH("indexes() all change", function() BENCH("indexes() all change", function()
@ -157,19 +186,24 @@ BENCH("indexes() all change", function()
local state = vide.source(data) local state = vide.source(data)
local _list = vide.indexes(state, function(v, i)
return {} vide.root(function()
local _list = vide.indexes(state, function(v, i)
return {}
end)
--state(state()) -- fill double buffer
for i, v in data do
data[i] = v + 1
end
START(N)
state(data)
return nil
end) end)
--state(state()) -- fill double buffer
for i, v in data do
data[i] = v + 1
end
START(N)
state(data)
end) end)
BENCH("indexes() all remove", function() BENCH("indexes() all remove", function()
@ -181,15 +215,19 @@ BENCH("indexes() all remove", function()
local state = vide.source(data) local state = vide.source(data)
local _list = vide.indexes(state, function(v, i) vide.root(function()
return {} local _list = vide.indexes(state, function(v, i)
return {}
end)
table.clear(data)
START(N)
state(data)
return nil
end) end)
table.clear(data)
START(N)
state(data)
end) end)
BENCH("values() no change", function() BENCH("values() no change", function()
@ -201,15 +239,19 @@ BENCH("values() no change", function()
local state = vide.source(data) local state = vide.source(data)
local _list = vide.values(state, function(v, i) vide.root(function()
return {} local _list = vide.values(state, function(v, i)
return {}
end)
state(state()) -- fill double buffer
START(N)
state(data)
return nil
end) end)
state(state()) -- fill double buffer
START(N)
state(data)
end) end)
BENCH("values() all change", function() BENCH("values() all change", function()
@ -221,20 +263,24 @@ BENCH("values() all change", function()
local state = vide.source(data) local state = vide.source(data)
local _list = vide.values(state, function(v, i) vide.root(function()
return {} local _list = vide.values(state, function(v, i)
return {}
end)
state(state()) -- 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)
state(data)
return nil
end) end)
state(state()) -- 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)
state(data)
end) end)
BENCH("values() all remove", function() BENCH("values() all remove", function()
@ -246,86 +292,44 @@ BENCH("values() all remove", function()
local state = vide.source(data) local state = vide.source(data)
local _list = vide.values(state, function(v, i) vide.root(function()
return {} local _list = vide.values(state, function(v, i)
return {}
end)
table.clear(data)
START(N)
state(data)
return nil
end) end)
table.clear(data)
START(N)
state(data)
end) end)
BENCH("register new cleanup", function() BENCH("register new cleanup", function()
local cleanup = vide.cleanup local cleanup = vide.cleanup
local cleaner = function() end vide.root(function()
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
end)
-- cleanup cleanups from previous benchmark return nil
;(collectgarbage :: any)("collect")
vide.step(0)
BENCH("repeat cleanup", function()
local cleanup = vide.cleanup
local foo = NO_INLINE(function(i)
cleanup(function()
-- return i -- uncomment to include overhead of closure creation
end)
end) end)
for i = 1, START(N) do
foo(i)
end
end) end)
-- cleanup cleanups from previous benchmark
;(collectgarbage :: any)("collect")
vide.step(0)
BENCH("cleanup gc check", function()
local cleanup = vide.cleanup
local cleaner = function() end
local callers = table.create(N)
for i = 1, N do
callers[i] = function()
cleanup(cleaner)
return i
end
callers[i]()
end
START(N)
vide.step(0)
end)
BENCH("cleanup gc removal", function()
START(N)
vide.step(0) -- cleanup from previous benchmark
end)
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