From 6acd0542944b65c8a751d4c859b45551769b3126 Mon Sep 17 00:00:00 2001 From: Aaron Smith <83140718+centau@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:06:15 +0100 Subject: [PATCH] Add `cleanup()` benchmarks --- test/benchmark.luau | 33 +++++++++++++++++++++++++++++++++ test/testkit.luau | 10 +++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/test/benchmark.luau b/test/benchmark.luau index f9bc37a..0d4e383 100644 --- a/test/benchmark.luau +++ b/test/benchmark.luau @@ -247,4 +247,37 @@ BENCH("values() all remove", function() state(data) end) +BENCH("register cleanup", function() + local cleanup = vide.cleanup + + local function foo(i) + cleanup(function() -- todo: why is this not causing allocations? + return i + end) + end + + for i = 1, START(N) do + foo(i) + end +end) + +BENCH("cleanup step", function() + local cleanup = vide.cleanup + + local ref = table.create(N) + + for i = 1, N do + ref[i] = function() + cleanup(function() end) + return i + end + + ref[i]() + end + + START(N) + + vide.step(0) +end) + return nil diff --git a/test/testkit.luau b/test/testkit.luau index d244d7f..544c7cc 100644 --- a/test/testkit.luau +++ b/test/testkit.luau @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- -- testkit.luau --- v0.7.0 +-- v0.7.1 -------------------------------------------------------------------------------- local color = { @@ -39,23 +39,27 @@ local color = { local function convert_units(unit: string, value: number): (number, string) local prefix_colors = { + [4] = color.red, [3] = color.red, [2] = color.yellow, [1] = color.yellow, [0] = color.green, [-1] = color.red, [-2] = color.yellow, - [-3] = color.green + [-3] = color.green, + [-4] = color.red } local prefixes = { + [4] = "T", [3] ="G", [2] ="M", [1] = "k", [0] = " ", [-1] = "m", [-2] = "u", - [-3] = "n" + [-3] = "n", + [-4] = "p" } local order = 0