[Tarantool-patches] [PATCH v1 luajit 23/41] perf: adjust ray in LuaJIT-benches

Sergey Kaplun skaplun at tarantool.org
Fri Dec 26 11:29:34 MSK 2025


Hi, Sergey!
Thanks for the review.
Fixed your comment and added the short benchmark description as
you suggested.

On 17.11.25, Sergey Bronnikov wrote:
> 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 @@

Added the comment with the short benchmark description, as we
discussed offline:

===================================================================
diff --git a/perf/LuaJIT-benches/ray.lua b/perf/LuaJIT-benches/ray.lua
index e9719941..fe31481b 100644
--- a/perf/LuaJIT-benches/ray.lua
+++ b/perf/LuaJIT-benches/ray.lua
@@ -1,3 +1,7 @@
+-- Benchmark to check the performance of FP arithmetics and
+-- structure accesses via modeling of ray tracing. The benchmark
+-- generates the fractal image of spheres in the PGM format.
+
 local bench = require("bench").new(arg)
 
 local sqrt = math.sqrt
===================================================================

> > +local bench = require("bench").new(arg)
> > +

<snipped>

> > +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

Fixed:

===================================================================
diff --git a/perf/LuaJIT-benches/ray.lua b/perf/LuaJIT-benches/ray.lua
index f7b76d0a..e9719941 100644
--- a/perf/LuaJIT-benches/ray.lua
+++ b/perf/LuaJIT-benches/ray.lua
@@ -121,8 +121,8 @@ bench:add({
     io.output("/dev/null")
   end,
   payload = function()
-    local iss = 1/ss
-    local gf = 255/(ss*ss)
+    local iss = 1 / ss
+    local gf = 255 / (ss * ss)
 
     delta = 1
     while delta * delta + 1 ~= 1 do
@@ -137,16 +137,16 @@ bench:add({
 
     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
+    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
+        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)))
+        io.write(string.char(math.floor(0.5 + g * gf)))
       end
     end
   end,
===================================================================

> > +    local gf = 255/(ss*ss)

<snipped>

I've also refactored the benchmark a bit to make it performance match
the original version:

===================================================================
diff --git a/perf/LuaJIT-benches/ray.lua b/perf/LuaJIT-benches/ray.lua
index fe31481b..f322b023 100644
--- a/perf/LuaJIT-benches/ray.lua
+++ b/perf/LuaJIT-benches/ray.lua
@@ -125,6 +125,9 @@ bench:add({
     io.output("/dev/null")
   end,
   payload = function()
+    -- Cache to avoid upvalue lookups.
+    local level, n, ss = level, n, ss
+
     local iss = 1 / ss
     local gf = 255 / (ss * ss)
 
===================================================================

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list