test: add patch benchmark

This commit is contained in:
Richard 2025-01-25 15:05:55 -08:00
parent d703990e5b
commit 884e6c0e8c
2 changed files with 70 additions and 24 deletions

View file

@ -4,29 +4,27 @@ local Charm = require(ReplicatedStorage.DevPackages.Charm)
local computed = Charm.computed local computed = Charm.computed
local atom = Charm.atom local atom = Charm.atom
local function parameterGenerator()
return atom(0)
end
local benchmarks = {
atom = function(_, state: any)
for _ = 1, 500 do
state(math.random(1, 2))
end
end,
computed = function(_, state: any)
computed(function()
return 2 * state()
end)
for _ = 1, 500 do
state(math.random(1, 2))
end
end,
}
return { return {
ParameterGenerator = parameterGenerator, ParameterGenerator = function() end,
Functions = benchmarks, Functions = {
atom = function()
local state = atom(0)
for _ = 1, 500 do
state(math.random(1, 2))
end
end,
computed = function()
local state = atom(0)
local _double = computed(function()
return 2 * state()
end)
for _ = 1, 500 do
state(math.random(1, 2))
end
end,
},
} }

View file

@ -0,0 +1,48 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local patch = require(ReplicatedStorage.DevPackages.CharmSync.patch)
local USERS = 1000
local function generate()
local users = {}
for user = 1, USERS do
users[user] = {
coins = math.random(1, 2),
gems = math.random(1, 2),
}
end
return { users = users }
end
local function update(state)
state = table.clone(state)
state.users = table.clone(state.users)
for user = 1, USERS do
if math.random() > 0.5 then
continue
end
state.users[user] = {
coins = math.random(1, 2),
gems = math.random(1, 2),
}
end
return state
end
return {
ParameterGenerator = function()
local state = generate()
return state, update(state)
end,
Functions = {
diff = function(_, a, b)
patch.diff(a, b)
end,
},
}