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

Sergey Kaplun skaplun at tarantool.org
Fri Dec 26 11:27:06 MSK 2025


Hi, Sergey!
Thanks for the review.
Please, consider my answers below.

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.
> > ---
> >   perf/LuaJIT-benches/partialsums.lua | 69 ++++++++++++++++++-----------
> >   1 file changed, 42 insertions(+), 27 deletions(-)
> >
> > diff --git a/perf/LuaJIT-benches/partialsums.lua b/perf/LuaJIT-benches/partialsums.lua
> > index 46bb9da3..ab24b30a 100644
> > --- a/perf/LuaJIT-benches/partialsums.lua
> > +++ b/perf/LuaJIT-benches/partialsums.lua

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

===================================================================
diff --git a/perf/LuaJIT-benches/partialsums.lua b/perf/LuaJIT-benches/partialsums.lua
index c9d48a2d..2e5967d2 100644
--- a/perf/LuaJIT-benches/partialsums.lua
+++ b/perf/LuaJIT-benches/partialsums.lua
@@ -1,3 +1,7 @@
+-- The benchmark to check the performance of FP arithmetic and
+-- math functions. Calculates the partial sums of several series
+-- in the single loop.
+
 local bench = require("bench").new(arg)
 
 local DEFAULT_N = 1e7
===================================================================

> > @@ -1,29 +1,44 @@
> > +local bench = require("bench").new(arg)
> >   
> > -local n = tonumber(arg[1])
> > -local function pr(fmt, x) io.write(string.format(fmt, x)) end
> > +local DEFAULT_N = 1e7
> > +local n = tonumber(arg[1]) or DEFAULT_N
> Why 1e7 is default?

It is the default for x86 arch. I've taken the values from PARAMS_x86,
since this is the most important architecture for the Tarantool, see the
commit message.

> >   
> > -local a1, a2, a3, a4, a5, a6, a7, a8, a9, alt = 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
> > -local sqrt, sin, cos = math.sqrt, math.sin, math.cos
> > -for k=1,n do
> > -  local k2, sk, ck = k*k, sin(k), cos(k)
> > -  local k3 = k2*k
> > -  a1 = a1 + (2/3)^k
> > -  a2 = a2 + 1/sqrt(k)
> > -  a3 = a3 + 1/(k2+k)
> > -  a4 = a4 + 1/(k3*sk*sk)
> > -  a5 = a5 + 1/(k3*ck*ck)
> > -  a6 = a6 + 1/k
> > -  a7 = a7 + 1/k2
> > -  a8 = a8 + alt/k
> > -  a9 = a9 + alt/(k+k-1)
> > -  alt = -alt
> > -end
> > -pr("%.9f\t(2/3)^k\n", a1)
> > -pr("%.9f\tk^-0.5\n", a2)
> > -pr("%.9f\t1/k(k+1)\n", a3)
> > -pr("%.9f\tFlint Hills\n", a4)
> > -pr("%.9f\tCookson Hills\n", a5)
> > -pr("%.9f\tHarmonic\n", a6)
> > -pr("%.9f\tRiemann Zeta\n", a7)
> > -pr("%.9f\tAlternating Harmonic\n", a8)
> > -pr("%.9f\tGregory\n", a9)
> 
> debug prints were lost, is it intentional?

It is not the debug print, but verification of program correctness, also
it prevents DCE by the compilers in the compiled languages.

Here it is tested by the checker function.

> 
> In a previous benches debug prints were left, but suppressed.

No, there are no debug prints. Output to suppress is the program
behaviour (like in the life benchmark) or the result of the program
(like in the k-nucleotide). Since it is rather huge, to avoid saving the
result in the file, it is better to drop it into the /dev/null to avoid
dependence on the file system.

> 
> Also I propose to use the same printf function in all benches for 
> consistency.

There is no need for it since this is not the main payload of the
benchmark.

> 
> > +bench:add({
> > +  name = "partialsums",
> > +  payload = function()
> > +    local a1, a2, a3, a4, a5, a6, a7, a8, a9, alt = 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
> > +    local sqrt, sin, cos = math.sqrt, math.sin, math.cos
> > +    for k=1,n do
> please add more whitespaces, here and below

Added:

===================================================================
diff --git a/perf/LuaJIT-benches/partialsums.lua b/perf/LuaJIT-benches/partialsums.lua
index ab24b30a..c9d48a2d 100644
--- a/perf/LuaJIT-benches/partialsums.lua
+++ b/perf/LuaJIT-benches/partialsums.lua
@@ -8,18 +8,18 @@ bench:add({
   payload = function()
     local a1, a2, a3, a4, a5, a6, a7, a8, a9, alt = 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
     local sqrt, sin, cos = math.sqrt, math.sin, math.cos
-    for k=1,n do
-      local k2, sk, ck = k*k, sin(k), cos(k)
-      local k3 = k2*k
-      a1 = a1 + (2/3)^k
-      a2 = a2 + 1/sqrt(k)
-      a3 = a3 + 1/(k2+k)
-      a4 = a4 + 1/(k3*sk*sk)
-      a5 = a5 + 1/(k3*ck*ck)
-      a6 = a6 + 1/k
-      a7 = a7 + 1/k2
-      a8 = a8 + alt/k
-      a9 = a9 + alt/(k+k-1)
+    for k = 1, n do
+      local k2, sk, ck = k * k, sin(k), cos(k)
+      local k3 = k2 * k
+      a1 = a1 + (2 / 3) ^ k
+      a2 = a2 + 1 / sqrt(k)
+      a3 = a3 + 1 / (k2 + k)
+      a4 = a4 + 1 / (k3 * sk * sk)
+      a5 = a5 + 1 / (k3 * ck * ck)
+      a6 = a6 + 1 / k
+      a7 = a7 + 1 / k2
+      a8 = a8 + alt / k
+      a9 = a9 + alt / (k + k - 1)
       alt = -alt
     end
     return {a1, a2, a3, a4, a5, a6, a7, a8, a9}
===================================================================

> > +      local k2, sk, ck = k*k, sin(k), cos(k)
> > +      local k3 = k2*k
> > +      a1 = a1 + (2/3)^k
> > +      a2 = a2 + 1/sqrt(k)
> > +      a3 = a3 + 1/(k2+k)
> > +      a4 = a4 + 1/(k3*sk*sk)
> > +      a5 = a5 + 1/(k3*ck*ck)
> > +      a6 = a6 + 1/k
> > +      a7 = a7 + 1/k2
> > +      a8 = a8 + alt/k
> > +      a9 = a9 + alt/(k+k-1)
> > +      alt = -alt
> > +    end
> > +    return {a1, a2, a3, a4, a5, a6, a7, a8, a9}
> > +  end,
> > +  checker = function(a)
> > +    if n == DEFAULT_N then
> > +      assert(a[1] == 2.99999999999999866773)
> > +      assert(a[2] == 6323.09512394020111969439)
> > +      assert(a[3] == 0.99999989999981531152)
> > +      assert(a[4] == 30.31454593111029183206)
> > +      assert(a[5] == 42.99523427973661426904)
> > +      assert(a[6] == 16.69531136585727182364)
> > +      assert(a[7] == 1.64493396684725956547)
> > +      assert(a[8] == 0.69314713056010635039)
> > +      assert(a[9] == 0.78539813839744787582)
> > +    end
> > +    return true
> > +  end,
> > +  items = n,
> > +})
> > +
> > +bench:run_and_report()
> >

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list