[Tarantool-patches] [PATCH v1 luajit 08/41] perf: adjust euler14-bit in LuaJIT-benches
Sergey Kaplun
skaplun at tarantool.org
Fri Dec 26 11:12:51 MSK 2025
Hi, Sergey!
Thanks for the review.
Fixed your comments and added the description for the benchmark.
On 13.11.25, Sergey Bronnikov wrote:
> Hi, Sergey,
>
> thanks for the patch!
>
> 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/euler14-bit.lua | 52 ++++++++++++++++++++---------
> > 1 file changed, 36 insertions(+), 16 deletions(-)
> >
> > diff --git a/perf/LuaJIT-benches/euler14-bit.lua b/perf/LuaJIT-benches/euler14-bit.lua
> > index 537f2bf3..7c521deb 100644
> > --- a/perf/LuaJIT-benches/euler14-bit.lua
> > +++ b/perf/LuaJIT-benches/euler14-bit.lua
> > @@ -1,22 +1,42 @@
Also, added the comment with the benchmark description as we discussed
offline.
===================================================================
diff --git a/perf/LuaJIT-benches/euler14-bit.lua b/perf/LuaJIT-benches/euler14-bit.lua
index 54311abe..c4ae3713 100644
--- a/perf/LuaJIT-benches/euler14-bit.lua
+++ b/perf/LuaJIT-benches/euler14-bit.lua
@@ -1,3 +1,8 @@
+-- The benchmark to check the performance of bitwise operations.
+-- It finds the longest Collatz sequence using bitwise arithmetic.
+-- For the details see:
+-- https://projecteuler.net/problem=14
+
local bench = require("bench").new(arg)
local bit = require("bit")
===================================================================
> > +local bench = require("bench").new(arg)
> >
> > local bit = require("bit")
> > local bnot, bor, band = bit.bnot, bit.bor, bit.band
> > local shl, shr = bit.lshift, bit.rshift
> >
<snipped>
> > +bench:add({
> > + name = "euler14_bit",
> > + payload = function()
> > + local cache, m, n = { 1 }, 1, 1
> > + if drop_cache then cache = nil end
> > + for i=2,N do
> s/2,/2, /
> > + local j = i
> > + for len=1,1000000000 do
> s/1,/1, /
> > + j = bor(band(shr(j,1), band(j,1)-1), band(shl(j,1)+j+1, bnot(band(j,1)-1)))
> please add whitespaces, here and below
> > + if cache then
> > + local x = cache[j]; if x then j = x+len; break end
> whitespaces
> > + elseif j == 1 then
> > + j = len+1; break
> s/+/ + /
Refactor this part of the code to make it more clear. See the iterative
patch below:
===================================================================
diff --git a/perf/LuaJIT-benches/euler14-bit.lua b/perf/LuaJIT-benches/euler14-bit.lua
index 7c521deb..54311abe 100644
--- a/perf/LuaJIT-benches/euler14-bit.lua
+++ b/perf/LuaJIT-benches/euler14-bit.lua
@@ -13,14 +13,22 @@ bench:add({
payload = function()
local cache, m, n = { 1 }, 1, 1
if drop_cache then cache = nil end
- for i=2,N do
+ for i = 2, N do
local j = i
- for len=1,1000000000 do
- j = bor(band(shr(j,1), band(j,1)-1), band(shl(j,1)+j+1, bnot(band(j,1)-1)))
+ for len = 1, 1000000000 do
+ j = bor(
+ band(shr(j, 1), band(j, 1) - 1),
+ band(shl(j, 1) + j + 1, bnot(band(j, 1) - 1))
+ )
if cache then
- local x = cache[j]; if x then j = x+len; break end
+ local x = cache[j]
+ if x then
+ j = x + len
+ break
+ end
elseif j == 1 then
- j = len+1; break
+ j = len + 1
+ break
end
end
if cache then cache[i] = j end
===================================================================
> > + end
> > + end
> > + if cache then cache[i] = j end
> > + if j > m then m, n = j, i end
> > + end
> > + return {n = n, m = m}
> > + end,
> > + checker = function(res)
<snipped>
> > +bench:run_and_report()
--
Best regards,
Sergey Kaplun
More information about the Tarantool-patches
mailing list