mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Add context()
This commit is contained in:
parent
83db00a073
commit
8142acd1c1
8 changed files with 303 additions and 1 deletions
|
|
@ -4,11 +4,14 @@ local BENCH, START = testkit.benchmark()
|
|||
local vide = require "src/init"
|
||||
local source = vide.source
|
||||
local derive = vide.derive
|
||||
local effect = vide.effect
|
||||
local indexes = vide.indexes
|
||||
local values = vide.values
|
||||
local batch = vide.batch
|
||||
local cleanup = vide.cleanup
|
||||
local untrack = vide.untrack
|
||||
local create = vide.create
|
||||
local context = vide.context
|
||||
|
||||
assert(not vide.strict)
|
||||
|
||||
|
|
@ -446,6 +449,61 @@ ROOT_BENCH("values() all remove", function()
|
|||
src(data)
|
||||
end)
|
||||
|
||||
TITLE "context()"
|
||||
|
||||
ROOT_BENCH("set context", function()
|
||||
local ctx = context()
|
||||
|
||||
for i = 1, START(N) do
|
||||
ctx(i, function() end)
|
||||
end
|
||||
end)
|
||||
|
||||
ROOT_BENCH("get context (depth=1)", function()
|
||||
local ctx = context()
|
||||
|
||||
local function run()
|
||||
for i = 1, START(N) do
|
||||
ctx()
|
||||
end
|
||||
end
|
||||
|
||||
ctx(1, function()
|
||||
run()
|
||||
end)
|
||||
end)
|
||||
|
||||
local depth = 10
|
||||
ROOT_BENCH(`get context (depth={depth})`, function()
|
||||
|
||||
local ctx = context()
|
||||
|
||||
local function run()
|
||||
for i = 1, START(N) do
|
||||
ctx()
|
||||
end
|
||||
end
|
||||
|
||||
local function nest_effect(fn)
|
||||
untrack(function()
|
||||
effect(fn)
|
||||
return nil
|
||||
end)
|
||||
end
|
||||
|
||||
local f = run
|
||||
for i = 1, depth - 1 do
|
||||
local f_inner = f
|
||||
f = function()
|
||||
nest_effect(f_inner)
|
||||
end
|
||||
end
|
||||
|
||||
ctx(1, function()
|
||||
f()
|
||||
end)
|
||||
end)
|
||||
|
||||
N *= 1024
|
||||
|
||||
TITLE "aggregate"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue