[Tarantool-patches] [PATCH v2 luajit 18/41] perf: adjust nsieve-bit-fp in LuaJIT-benches

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


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-bit-fp.lua | 42 +++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/perf/LuaJIT-benches/nsieve-bit-fp.lua b/perf/LuaJIT-benches/nsieve-bit-fp.lua
index 3971ec1f..ae1d1a1f 100644
--- a/perf/LuaJIT-benches/nsieve-bit-fp.lua
+++ b/perf/LuaJIT-benches/nsieve-bit-fp.lua
@@ -1,3 +1,11 @@
+-- Benchmark to check the performance of FP arithmetics and
+-- access to the array structure. This benchmark finds all prime
+-- numbers in a given segment. This is the FP benchmark that
+-- models the bit variation behaviour.
+-- For the details see:
+-- https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
+
+local bench = require("bench").new(arg)
 
 local floor, ceil = math.floor, math.ceil
 
@@ -27,11 +35,35 @@ local function nsieve(p, m)
   return count
 end
 
-local N = tonumber(arg and arg[1]) or 1
+local DEFAULT_N = 12
+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_bit_fp",
+  payload = function()
+    local res = {}
+    local items = 0
+    for i = 0, 2 do
+      local m = (2 ^ (N - i)) * 10000
+      items = items + m
+      res[i] = nsieve(primes, m)
+    end
+    benchmark.items = items
+
+    return res
+  end,
+  checker = function(res)
+    if N == DEFAULT_N then
+      assert(res[0] == 2488465)
+      assert(res[1] == 1299069)
+      assert(res[2] == 679461)
+    end
+    return true
+  end,
+}
+
+bench:add(benchmark)
+bench:run_and_report()
-- 
2.52.0



More information about the Tarantool-patches mailing list