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

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


Hi, Sergey!
Thanks for the review!
See 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/nsieve.lua | 35 +++++++++++++++++++++++++++++-----
> >   1 file changed, 30 insertions(+), 5 deletions(-)
> >
> > diff --git a/perf/LuaJIT-benches/nsieve.lua b/perf/LuaJIT-benches/nsieve.lua
> > index 6de0524f..2d1b66c8 100644
> > --- a/perf/LuaJIT-benches/nsieve.lua
> > +++ b/perf/LuaJIT-benches/nsieve.lua
> > @@ -1,3 +1,4 @@

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

===================================================================
diff --git a/perf/LuaJIT-benches/nsieve.lua b/perf/LuaJIT-benches/nsieve.lua
index 1eb4efe8..dd59c71c 100644
--- a/perf/LuaJIT-benches/nsieve.lua
+++ b/perf/LuaJIT-benches/nsieve.lua
@@ -1,3 +1,10 @@
+-- Benchmark to check the performance of access to the array
+-- structure in the tiny inner loops. This benchmark finds all the
+-- prime numbers in a given segment. This is the most
+-- straightforward implementation.
+-- For the details see:
+-- https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
+
 local bench = require("bench").new(arg)
 
 local function nsieve(p, m)
===================================================================

> > +local bench = require("bench").new(arg)
> >   
> >   local function nsieve(p, m)
> >     for i=2,m do p[i] = true end
> > @@ -11,11 +12,35 @@ local function nsieve(p, m)
> >     return count
> >   end
> >   
> > -local N = tonumber(arg and arg[1]) or 1
> > +local DEFAULT_N = 12
> Why 12?

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 N = tonumber(arg and arg[1]) or DEFAULT_N
> >   if N < 2 then N = 2 end
> >   local primes = {}
> >   
> > -for i=0,2 do
> > -  local m = (2^(N-i))*10000
> > -  io.write(string.format("Primes up to %8d %8d\n", m, nsieve(primes, m)))
> > -end
> > +local benchmark
> > +benchmark = {
> > +  name = "nsieve",
> > +  payload = function()
> > +    local res = {}
> > +    local items = 0
> > +    for i=0,2 do
> add more whitespaces, here and below

Fixed:

===================================================================
diff --git a/perf/LuaJIT-benches/nsieve.lua b/perf/LuaJIT-benches/nsieve.lua
index 2d1b66c8..1eb4efe8 100644
--- a/perf/LuaJIT-benches/nsieve.lua
+++ b/perf/LuaJIT-benches/nsieve.lua
@@ -23,8 +23,8 @@ benchmark = {
   payload = function()
     local res = {}
     local items = 0
-    for i=0,2 do
-      local m = (2^(N-i))*10000
+    for i = 0, 2 do
+      local m = (2 ^ (N - i)) * 10000
       items = items + m
       res[i] = nsieve(primes, m)
     end
===================================================================

> > +      local m = (2^(N-i))*10000

<snipped>

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list