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

Sergey Kaplun skaplun at tarantool.org
Fri Dec 26 11:20:45 MSK 2025


Hi, Sergey!
Thanks for the review.
Fixed you comments and added the description for the benchmark.

On 23.12.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/mandelbrot.lua | 64 +++++++++++++++++++++---------
> >   1 file changed, 45 insertions(+), 19 deletions(-)
> >
> > diff --git a/perf/LuaJIT-benches/mandelbrot.lua b/perf/LuaJIT-benches/mandelbrot.lua
> > index 0ef595a2..51e0dd4f 100644
> > --- a/perf/LuaJIT-benches/mandelbrot.lua
> > +++ b/perf/LuaJIT-benches/mandelbrot.lua
> > @@ -1,23 +1,49 @@

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

===================================================================
diff --git a/perf/LuaJIT-benches/mandelbrot.lua b/perf/LuaJIT-benches/mandelbrot.lua
index 8b7310b8..999ff200 100644
--- a/perf/LuaJIT-benches/mandelbrot.lua
+++ b/perf/LuaJIT-benches/mandelbrot.lua
@@ -1,3 +1,9 @@
+-- The benchmark to check the performance of multiple inner loops
+-- with arithmetic operations. Calculates the Mandelbrot Set on a
+-- bitmap and dumps output in the portable bitmap format.
+-- For the details see:
+-- https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/mandelbrot.html
+
 local bench = require("bench").new(arg)
 
 local N = tonumber(arg and arg[1]) or 5000
===================================================================

> > +local bench = require("bench").new(arg)
> >   
> > -local write, char, unpack = io.write, string.char, unpack
> > -local N = tonumber(arg and arg[1]) or 100
> > -local M, ba, bb, buf = 2/N, 2^(N%8+1)-1, 2^(8-N%8), {}
> > -write("P4\n", N, " ", N, "\n")
> > -for y=0,N-1 do
> > -  local Ci, b, p = y*M-1, 1, 0
> > -  for x=0,N-1 do
> > -    local Cr = x*M-1.5
> > -    local Zr, Zi, Zrq, Ziq = Cr, Ci, Cr*Cr, Ci*Ci
> > -    b = b + b
> > -    for i=1,49 do
> > -      Zi = Zr*Zi*2 + Ci
> > -      Zr = Zrq-Ziq + Cr
> > -      Ziq = Zi*Zi
> > -      Zrq = Zr*Zr
> > -      if Zrq+Ziq > 4.0 then b = b + 1; break; end
> > +local N = tonumber(arg and arg[1]) or 5000
> > +
> > +local function payload()
> > +  -- These functions must not be an upvalue but the stack slot.
> > +  local N = N
> > +  local write, char, unpack = io.write, string.char, unpack
> > +  local M, ba, bb, buf = 2/N, 2^(N%8+1)-1, 2^(8-N%8), {}
> please add more whitespaces. Here and below.

Rewritten as you suggested:

===================================================================
diff --git a/perf/LuaJIT-benches/mandelbrot.lua b/perf/LuaJIT-benches/mandelbrot.lua
index 51e0dd4f..8b7310b8 100644
--- a/perf/LuaJIT-benches/mandelbrot.lua
+++ b/perf/LuaJIT-benches/mandelbrot.lua
@@ -6,24 +6,24 @@ local function payload()
   -- These functions must not be an upvalue but the stack slot.
   local N = N
   local write, char, unpack = io.write, string.char, unpack
-  local M, ba, bb, buf = 2/N, 2^(N%8+1)-1, 2^(8-N%8), {}
+  local M, ba, bb, buf = 2 / N, 2 ^ (N % 8 + 1) - 1, 2 ^ (8 - N % 8), {}
   write("P4\n", N, " ", N, "\n")
-  for y=0,N-1 do
-    local Ci, b, p = y*M-1, 1, 0
-    for x=0,N-1 do
-      local Cr = x*M-1.5
-      local Zr, Zi, Zrq, Ziq = Cr, Ci, Cr*Cr, Ci*Ci
+  for y = 0, N - 1 do
+    local Ci, b, p = y * M - 1, 1, 0
+    for x = 0, N - 1 do
+      local Cr = x * M - 1.5
+      local Zr, Zi, Zrq, Ziq = Cr, Ci, Cr * Cr, Ci * Ci
       b = b + b
-      for i=1,49 do
-        Zi = Zr*Zi*2 + Ci
-        Zr = Zrq-Ziq + Cr
-        Ziq = Zi*Zi
-        Zrq = Zr*Zr
-        if Zrq+Ziq > 4.0 then b = b + 1; break; end
+      for i = 1, 49 do
+        Zi = Zr * Zi * 2 + Ci
+        Zr = Zrq - Ziq + Cr
+        Ziq = Zi * Zi
+        Zrq = Zr * Zr
+        if Zrq + Ziq > 4.0 then b = b + 1; break; end
       end
       if b >= 256 then p = p + 1; buf[p] = 511 - b; b = 1; end
     end
-    if b ~= 1 then p = p + 1; buf[p] = (ba-b)*bb; end
+    if b ~= 1 then p = p + 1; buf[p] = (ba - b) * bb; end
     write(char(unpack(buf, 1, p)))
   end
 end
===================================================================

> > +  write("P4\n", N, " ", N, "\n")

<snipped>

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list