From 21dcbc695e64d80f0615099e5e5beeda0f7c6882 Mon Sep 17 00:00:00 2001 From: 4DBug <4DBug@github.com> Date: Wed, 21 Oct 2026 01:58:35 -0500 Subject: [PATCH] tools/test: bench_scenes.luau (plots, colorpicker, implot, demo_all scenes shared by the Studio bench and headless runs) and t_stress2.luau (library + backend time and draw checksum per scene) --- tools/test/bench_scenes.luau | 112 ++++++++++++++++++++++++++++++ tools/test/scripts/t_stress2.luau | 55 +++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 tools/test/bench_scenes.luau create mode 100644 tools/test/scripts/t_stress2.luau diff --git a/tools/test/bench_scenes.luau b/tools/test/bench_scenes.luau new file mode 100644 index 0000000..0d2cfb9 --- /dev/null +++ b/tools/test/bench_scenes.luau @@ -0,0 +1,112 @@ +-- Benchmark scenes shared by the Studio bench (slopgame place, ReplicatedStorage.Shared.BenchScenes) and the headless +-- tools/test/scripts/t_stress2.luau. Deterministic: everything animates from the frame number f, never from time. +-- return function(G, ImPlot?) -> { plots = fn(f), colorpicker = fn(f), implot = fn(f) (if ImPlot), demo_all = fn(f) } +return function(G, ImPlot) + local ImGui, ImVec2, ImVec4 = G.ImGui, G.ImVec2, G.ImVec4 + local Cond = G.ImGuiCond + local S = { values = table.create(90, 0), col1 = ImVec4(0.4, 0.7, 0.2, 0.5), col2 = ImVec4(0.9, 0.3, 0.6, 0.8), + edits = { ImVec4(1, 0, 0, 1), ImVec4(0, 1, 0, 0.5), ImVec4(0, 0, 1, 1), ImVec4(1, 1, 0, 0.25) } } + local scenes = {} + + local function Place(name, x, y, w, h) + ImGui.SetNextWindowPos(ImVec2(x, y), Cond.Always) + ImGui.SetNextWindowSize(ImVec2(w, h), Cond.Always) + return ImGui.Begin(name) + end + + -- PlotLines + PlotHistogram over a 90-sample ring buffer, one new sample per frame (demo "Plots Widgets" pattern) + function scenes.plots(f) + local v = S.values + local off = f % 90 + v[off + 1] = math.sin(f * 0.13) * 0.7 + math.sin(f * 0.031) * 0.3 + Place("Plots", 60, 60, 520, 640) + ImGui.PlotLines("Lines", v, nil, 90, off, "avg", -1.0, 1.0, ImVec2(0, 120)) + ImGui.PlotHistogram("Histogram", v, nil, 90, off, nil, -1.0, 1.0, ImVec2(0, 120)) + ImGui.PlotLines("Lines small", v, nil, 90, off, nil, -1.0, 1.0, ImVec2(0, 60)) + ImGui.PlotHistogram("Histogram small", v, nil, 90, off, nil, -1.0, 1.0, ImVec2(0, 60)) + ImGui.End() + end + + -- ColorPicker4 with hue bar and with hue wheel (+ alpha bars), colour animated every frame, plus ColorEdit4s + function scenes.colorpicker(f) + local h = (f * 0.005) % 1 + local r, g, b = ImGui.ColorConvertHSVtoRGB(h, 0.7, 0.9) + S.col1.x, S.col1.y, S.col1.z = r, g, b + r, g, b = ImGui.ColorConvertHSVtoRGB((h + 0.5) % 1, 0.5, 0.8) + S.col2.x, S.col2.y, S.col2.z = r, g, b + local F = G.ImGuiColorEditFlags + Place("Colors", 60, 60, 520, 640) + ImGui.ColorPicker4("bar", S.col1, bit32.bor(F.PickerHueBar, F.AlphaBar)) + ImGui.ColorPicker4("wheel", S.col2, bit32.bor(F.PickerHueWheel, F.AlphaBar)) + for i, c in S.edits do ImGui.ColorEdit4("edit " .. i, c) end + ImGui.End() + end + + if ImPlot then + local xs, ys, sx, sy, bars, xs101, y1, y2, heat = {}, {}, {}, {}, {}, {}, {}, {}, {} + for i = 1, 1001 do xs[i] = (i - 1) * 0.001 end + for i = 1, 100 do + sx[i] = ((i * 7919) % 1000) / 1000 + sy[i] = ((i * 104729) % 1000) / 1000 + end + for i = 1, 101 do xs101[i] = i - 1 end + -- line (1001 pts, animated), scatter (100 pts), bars (10, animated), shaded (2x101, animated), heatmap (10x10, animated) + function scenes.implot(f) + for i = 1, 1001 do ys[i] = 0.5 + 0.5 * math.sin(50 * (xs[i] + f * 0.002)) end + for i = 1, 10 do bars[i] = 5 + 4 * math.sin(f * 0.05 + i) end + for i = 1, 101 do + y1[i] = 250 + 100 * math.sin((i + f) * 0.07) + y2[i] = 200 + 80 * math.cos((i + f) * 0.05) + end + for i = 1, 100 do heat[i] = 0.5 + 0.5 * math.sin(i * 0.37 + f * 0.04) end + Place("ImPlot", 60, 60, 620, 900) + local sz = ImVec2(-1, 200) + if ImPlot.BeginPlot("Line", sz) then + ImPlot.SetupAxesLimits(0, 1, 0, 1, Cond.Always) + ImPlot.PlotLine("f(x)", xs, ys, 1001) + ImPlot.EndPlot() + end + if ImPlot.BeginPlot("Scatter + Bars", sz) then + ImPlot.SetupAxesLimits(0, 10, 0, 10, Cond.Always) + ImPlot.PlotBars("bars", bars, 10, 0.7, 0) + local sxx, syy = {}, {} + for i = 1, 100 do sxx[i], syy[i] = sx[i] * 10, sy[i] * 10 end + ImPlot.PlotScatter("pts", sxx, syy, 100) + ImPlot.EndPlot() + end + if ImPlot.BeginPlot("Shaded", sz) then + ImPlot.SetupAxesLimits(0, 100, 0, 500, Cond.Always) + ImPlot.PlotShaded("a", xs101, y1, 101, 0) + ImPlot.PlotShaded("b", xs101, y2, 101, 0) + ImPlot.PlotLine("a", xs101, y1, 101) + ImPlot.PlotLine("b", xs101, y2, 101) + ImPlot.EndPlot() + end + if ImPlot.BeginPlot("##Heatmap", ImVec2(220, 220)) then + ImPlot.PlotHeatmap("heat", heat, 10, 10, 0, 1, "%.1f") + ImPlot.EndPlot() + end + ImGui.End() + end + end + + -- the whole demo window, every CollapsingHeader / TreeNode forced open, static + local realCH, realTN, forcing = ImGui.CollapsingHeader, ImGui.TreeNode, false + ImGui.CollapsingHeader = function(label, ...) + if forcing then ImGui.SetNextItemOpen(true, Cond.Always) end + return realCH(label, ...) + end + ImGui.TreeNode = function(label, ...) + if forcing then ImGui.SetNextItemOpen(true, Cond.Always) end + return realTN(label, ...) + end + function scenes.demo_all(f) + ImGui.SetNextWindowPos(ImVec2(60, 40), Cond.Always) + ImGui.SetNextWindowSize(ImVec2(620, 900), Cond.Always) + forcing = true + ImGui.ShowDemoWindow() + forcing = false + end + + return scenes +end diff --git a/tools/test/scripts/t_stress2.luau b/tools/test/scripts/t_stress2.luau new file mode 100644 index 0000000..3e8ac2d --- /dev/null +++ b/tools/test/scripts/t_stress2.luau @@ -0,0 +1,55 @@ +-- Headless twin of the Studio bench's round-3 scenes (tools/test/bench_scenes.luau): plots, colorpicker, implot, +-- demo_all. Prints the median / lower-quartile library time (NewFrame..Render) and backend time (RenderDrawData), and a +-- checksum of the draw data (must not change with internal optimizations). +-- RUN_FLAGS="ARG_MODE='plots'" python3 tools/test/run.py --main tools/test/scripts/t_stress2.luau --frames 400 --quiet --roblox \ +-- --module BenchScenes=tools/test/bench_scenes.luau [--module ImPlot=../implot-luau/ImPlot.lua] +local RS = game:GetService("ReplicatedStorage") +local G = require(RS:WaitForChild("ImGui")) +local ImGui = G.ImGui +local ImPlot = RS:FindFirstChild("ImPlot") and require(RS.ImPlot)(G) +ImGui.CreateContext() +if ImPlot then ImPlot.CreateContext() end +G.ImGui_ImplRoblox.Init() +G.ImGui_ImplRoblox.SetRenderRate(0) +local io = ImGui.GetIO() +local MODE = type(ARG_MODE) == "string" and ARG_MODE or "plots" +local scene = require(RS:WaitForChild("BenchScenes"))(G, ImPlot)[MODE] +assert(scene, "unknown or unavailable scene " .. MODE) +local clock = os.realclock or os.clock + +local frame, h, lib, be = 0, 0, {}, {} +local function mix(v) h = (h * 31 + math.floor(v * 64 + 0.5)) % 2147483647 end +local function stats(t) + table.sort(t) + local lo = 0 + for i = 1, #t // 4 do lo += t[i] end + return t[#t // 2 + 1] * 1000, lo / (#t // 4) * 1000 +end +game:GetService("RunService").Stepped:Connect(function() + frame += 1 + G.ImGui_ImplRoblox.NewFrame() + io.DeltaTime = 1 / 60 + io:AddMousePosEvent(-1000, -1000) + local t0 = clock() + ImGui.NewFrame() + scene(frame) + ImGui.Render() + local t1 = clock() + local dd = ImGui.GetDrawData() + for _, dl in dd.CmdLists:iter() do + local vb, id = dl.VtxBuffer.Buf, dl.IdxBuffer.Data + for i = 1, dl.VtxBuffer.Size do local o = (i - 1) * 36; mix(buffer.readf64(vb, o)); mix(buffer.readf64(vb, o + 8)); mix(buffer.readf64(vb, o + 16) * 4096); mix(buffer.readf64(vb, o + 24) * 4096); mix(buffer.readu32(vb, o + 32) / 64) end + for i = 1, dl.IdxBuffer.Size do mix(id[i]) end + for _, c in dl.CmdBuffer:iter() do mix(c.ClipRect.x); mix(c.ClipRect.y); mix(c.ClipRect.z); mix(c.ClipRect.w); mix(c.ElemCount) end + end + local t2 = clock() + G.ImGui_ImplRoblox.RenderDrawData(dd) + local t3 = clock() + if frame > 20 then table.insert(lib, t1 - t0); table.insert(be, t3 - t2) end + if frame == ARG_FRAMES - 1 then + local lm, ll = stats(lib) + local bm, bl = stats(be) + print(string.format("STRESS2 %s lib med %.3f lowq %.3f ms | backend med %.3f lowq %.3f ms", MODE, lm, ll, bm, bl)) + print("STRESS2HASH", MODE, h) + end +end)