mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
This commit is contained in:
parent
574eb8e4c5
commit
7a9d7ccc12
1 changed files with 148 additions and 144 deletions
|
|
@ -15,9 +15,10 @@ local vide = require "src/init"
|
|||
local N = 2^18 -- 262144[
|
||||
|
||||
BENCH("create state", function()
|
||||
local cache = table.create(N)
|
||||
local source = vide.source
|
||||
|
||||
local cache = table.create(N)
|
||||
|
||||
for i = 1, START(N) do
|
||||
cache[i] = source(1)
|
||||
end
|
||||
|
|
@ -40,39 +41,53 @@ BENCH("set value", function()
|
|||
end)
|
||||
|
||||
BENCH("derive 1 state", function()
|
||||
local cache = table.create(N)
|
||||
local state = vide.source(1)
|
||||
local derive = vide.derive
|
||||
|
||||
local cache = table.create(N)
|
||||
local state = vide.source(1)
|
||||
|
||||
vide.root(function()
|
||||
for i = 1, START(N) do
|
||||
cache[i] = derive(function()
|
||||
return state()
|
||||
end)
|
||||
end
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("derive 4 states", function()
|
||||
local derive = vide.derive
|
||||
|
||||
local cache = table.create(N)
|
||||
local state = vide.source(1)
|
||||
local state2 = vide.source(2)
|
||||
local state3 = vide.source(3)
|
||||
local state4 = vide.source(4)
|
||||
local derive = vide.derive
|
||||
|
||||
vide.root(function()
|
||||
for i = 1, START(N) do
|
||||
cache[i] = derive(function()
|
||||
return state() + state2() + state3() + state4()
|
||||
end)
|
||||
end
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("set derived value", function()
|
||||
local state = vide.source(1)
|
||||
|
||||
vide.root(function()
|
||||
local _derived = vide.derive(state)
|
||||
|
||||
for i = 1, START(N) do
|
||||
state(i)
|
||||
end
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("apply 0 properties", function()
|
||||
|
|
@ -104,21 +119,28 @@ end)
|
|||
|
||||
BENCH("bind source", function()
|
||||
local apply = require "src/apply"
|
||||
|
||||
local instance = vide.create("Frame") {}
|
||||
local state = vide.source(1)
|
||||
|
||||
vide.root(function()
|
||||
for i = 1, START(N) do
|
||||
apply(instance, {
|
||||
Name = state
|
||||
})
|
||||
end
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("update binding", function()
|
||||
local apply = require "src/apply"
|
||||
|
||||
local instance = vide.create("Frame") {}
|
||||
local state = vide.source(1)
|
||||
|
||||
vide.root(function()
|
||||
apply(instance, {
|
||||
Name = state
|
||||
})
|
||||
|
|
@ -126,6 +148,9 @@ BENCH("update binding", function()
|
|||
for i = 1, START(N) do
|
||||
state(i)
|
||||
end
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("indexes() no change", function()
|
||||
|
|
@ -137,6 +162,7 @@ BENCH("indexes() no change", function()
|
|||
|
||||
local state = vide.source(data)
|
||||
|
||||
vide.root(function()
|
||||
local _list = vide.indexes(state, function(v, i)
|
||||
return {}
|
||||
end)
|
||||
|
|
@ -146,6 +172,9 @@ BENCH("indexes() no change", function()
|
|||
START(N)
|
||||
|
||||
state(data)
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("indexes() all change", function()
|
||||
|
|
@ -157,6 +186,8 @@ BENCH("indexes() all change", function()
|
|||
|
||||
local state = vide.source(data)
|
||||
|
||||
|
||||
vide.root(function()
|
||||
local _list = vide.indexes(state, function(v, i)
|
||||
return {}
|
||||
end)
|
||||
|
|
@ -170,6 +201,9 @@ BENCH("indexes() all change", function()
|
|||
START(N)
|
||||
|
||||
state(data)
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("indexes() all remove", function()
|
||||
|
|
@ -181,6 +215,7 @@ BENCH("indexes() all remove", function()
|
|||
|
||||
local state = vide.source(data)
|
||||
|
||||
vide.root(function()
|
||||
local _list = vide.indexes(state, function(v, i)
|
||||
return {}
|
||||
end)
|
||||
|
|
@ -190,6 +225,9 @@ BENCH("indexes() all remove", function()
|
|||
START(N)
|
||||
|
||||
state(data)
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("values() no change", function()
|
||||
|
|
@ -201,6 +239,7 @@ BENCH("values() no change", function()
|
|||
|
||||
local state = vide.source(data)
|
||||
|
||||
vide.root(function()
|
||||
local _list = vide.values(state, function(v, i)
|
||||
return {}
|
||||
end)
|
||||
|
|
@ -210,6 +249,9 @@ BENCH("values() no change", function()
|
|||
START(N)
|
||||
|
||||
state(data)
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("values() all change", function()
|
||||
|
|
@ -221,6 +263,7 @@ BENCH("values() all change", function()
|
|||
|
||||
local state = vide.source(data)
|
||||
|
||||
vide.root(function()
|
||||
local _list = vide.values(state, function(v, i)
|
||||
return {}
|
||||
end)
|
||||
|
|
@ -235,6 +278,9 @@ BENCH("values() all change", function()
|
|||
START(N)
|
||||
|
||||
state(data)
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("values() all remove", function()
|
||||
|
|
@ -246,6 +292,7 @@ BENCH("values() all remove", function()
|
|||
|
||||
local state = vide.source(data)
|
||||
|
||||
vide.root(function()
|
||||
local _list = vide.values(state, function(v, i)
|
||||
return {}
|
||||
end)
|
||||
|
|
@ -255,11 +302,15 @@ BENCH("values() all remove", function()
|
|||
START(N)
|
||||
|
||||
state(data)
|
||||
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
BENCH("register new cleanup", function()
|
||||
local cleanup = vide.cleanup
|
||||
|
||||
vide.root(function()
|
||||
local cleaner = function() end
|
||||
|
||||
local callers = {}
|
||||
|
|
@ -274,58 +325,11 @@ BENCH("register new cleanup", function()
|
|||
for i = 1, START(N) do
|
||||
callers[i](cleanup, cleaner)
|
||||
end
|
||||
end)
|
||||
|
||||
-- cleanup cleanups from previous benchmark
|
||||
;(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
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
|
||||
for i = 1, START(N) do
|
||||
foo(i)
|
||||
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
|
||||
-- the purpose of the two following benchmarks is to measure the overhead of
|
||||
-- aggregate construction
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue