mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
feat: use alien-signals
This commit is contained in:
parent
d7a1f62c3c
commit
861ee5acd7
76 changed files with 3112 additions and 1862 deletions
61
tests/benchmarks/propagate.luau
Normal file
61
tests/benchmarks/propagate.luau
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
local Charm = require("../../packages/charm/src/lib")
|
||||
|
||||
local atom = Charm.atom
|
||||
local computed = Charm.computed
|
||||
local effect = Charm.effect
|
||||
|
||||
local signals = require("../../packages/charm/src/signals")
|
||||
|
||||
local signal = signals.signal
|
||||
local computedSignal = signals.computed
|
||||
local effectSignal = signals.effect
|
||||
|
||||
local w = 10
|
||||
local h = 10
|
||||
|
||||
local function bench(name: string, test: () -> ())
|
||||
local start = os.clock()
|
||||
local iter = 0
|
||||
for _ = 1, 15000 do
|
||||
iter += 1
|
||||
test()
|
||||
end
|
||||
local endTime = os.clock()
|
||||
local elapsed = endTime - start
|
||||
print(`{name}: {elapsed / iter * 1000 * 1000} us/iter`)
|
||||
end
|
||||
|
||||
bench(`charm {w} * {h}`, function()
|
||||
local src = atom(1)
|
||||
for _ = 1, w do
|
||||
local last = src
|
||||
for _ = 1, h do
|
||||
local prev = last
|
||||
last = computed(function()
|
||||
return prev() + 1
|
||||
end)
|
||||
end
|
||||
effect(function()
|
||||
last()
|
||||
end)
|
||||
end
|
||||
src(src() + 1)
|
||||
end)
|
||||
|
||||
bench(`alien-signals {w} * {h}`, function()
|
||||
local src = signal(1)
|
||||
for _ = 1, w do
|
||||
local last = src
|
||||
for _ = 1, h do
|
||||
local prev = last
|
||||
last = computedSignal(function()
|
||||
return prev() + 1
|
||||
end)
|
||||
end
|
||||
effectSignal(function()
|
||||
last()
|
||||
return nil
|
||||
end)
|
||||
end
|
||||
src(src() + 1)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue