Hi, Sergey,

thanks for the patch! See my comments.

Sergey

On 10/24/25 13:50, Sergey Kaplun wrote:
This patch adjusts the aforementioned test to use the benchmark
framework introduced before. The default arguments are adjusted
according to the <PARAM_x86.txt> file. The arguments to the script still
can be provided in the command line run.

The output is redirected to /dev/null. The check is skipped since it is
very inconvenient to check the binary output, especially since it may be
configured by the parameter.
---
 perf/LuaJIT-benches/ray.lua | 76 ++++++++++++++++++++++++-------------
 1 file changed, 50 insertions(+), 26 deletions(-)

diff --git a/perf/LuaJIT-benches/ray.lua b/perf/LuaJIT-benches/ray.lua
index 2acc24c0..f7b76d0a 100644
--- a/perf/LuaJIT-benches/ray.lua
+++ b/perf/LuaJIT-benches/ray.lua
@@ -1,10 +1,8 @@
+local bench = require("bench").new(arg)
+
 local sqrt = math.sqrt
 local huge = math.huge
-
-local delta = 1
-while delta * delta + 1 ~= 1 do
-  delta = delta * 0.5
-end
+local delta
 
 local function length(x, y, z)  return sqrt(x*x + y*y + z*z) end
 local function vlen(v)          return length(v[1], v[2], v[3]) end
@@ -110,26 +108,52 @@ end
 
 
 local level, n, ss = tonumber(arg[1]) or 9, tonumber(arg[2]) or 256, 4
-local iss = 1/ss
-local gf = 255/(ss*ss)
-
-io.write(("P5\n%d %d\n255\n"):format(n, n))
-local light = { unitise(-1, -3, 2) }
-ilight = { -light[1], -light[2], -light[3] }
-local camera = { 0, 0, -4 }
-local dir = { 0, 0, 0 }
-
-local scene = create(level, {0, -1, 0}, 1)
-
-for y = n/2-1, -n/2, -1 do
-  for x = -n/2, n/2-1 do
-    local g = 0
-    for d = y, y+.99, iss do
-      for e = x, x+.99, iss do
-        dir[1], dir[2], dir[3] = unitise(e, d, n)
-        g = g + ray_trace(light, camera, dir, scene) 
+
+local stdout = io.output()
+
+bench:add({
+  name = "ray",
+  -- Avoid skip checking here, since it is not very convenient.
+  -- If you want to check the behaviour -- drop the setup
+  -- function.
+  skip_check = true,
+  setup = function()
+    io.output("/dev/null")
+  end,
+  payload = function()
+    local iss = 1/ss
please add more whitespaces, here and below
+    local gf = 255/(ss*ss)
+
+    delta = 1
+    while delta * delta + 1 ~= 1 do
+      delta = delta * 0.5
+    end
+
+    io.write(("P5\n%d %d\n255\n"):format(n, n))
+    local light = { unitise(-1, -3, 2) }
+    ilight = { -light[1], -light[2], -light[3] }
+    local camera = { 0, 0, -4 }
+    local dir = { 0, 0, 0 }
+
+    local scene = create(level, {0, -1, 0}, 1)
+
+    for y = n/2-1, -n/2, -1 do
+      for x = -n/2, n/2-1 do
+        local g = 0
+        for d = y, y+.99, iss do
+          for e = x, x+.99, iss do
+            dir[1], dir[2], dir[3] = unitise(e, d, n)
+            g = g + ray_trace(light, camera, dir, scene)
+          end
+        end
+        io.write(string.char(math.floor(0.5 + g*gf)))
       end
     end
-    io.write(string.char(math.floor(0.5 + g*gf)))
-  end
-end
+  end,
+  teardown = function()
+    io.output(stdout)
+  end,
+  items = n * n * level,
+})
+
+bench:run_and_report()