charm/src/__tests__/benchmarks/atom.bench.luau
2024-03-25 18:57:22 -07:00

46 lines
962 B
Lua

-- This file is for use by Benchmarker
-- https://boatbomber.itch.io/benchmarker
local Package = game:GetService("ReplicatedStorage").Packages.charm
local atom = require(Package.atom)
local derive = require(Package.derive)
local function parameterGenerator()
return atom({ count = 0 })
end
local benchmarks = {
atom = function(_, source: any)
for _ = 1, 500 do
source({ count = math.random(1, 2) })
end
end,
derived = function(_, source: any)
derive(function()
return { count = 2 * source().count }
end)
for _ = 1, 500 do
source({ count = math.random(1, 2) })
end
end,
derived_memo = function(_, source: any)
derive(function()
return { count = 2 * source().count }
end, {
equals = function(previous, current)
return previous.count == current.count
end,
})
for _ = 1, 500 do
source({ count = math.random(1, 2) })
end
end,
}
return {
ParameterGenerator = parameterGenerator,
Functions = benchmarks,
}