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

Sergey Kaplun skaplun at tarantool.org
Fri Dec 26 11:24:41 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/nbody.lua | 127 ++++++++++++++++++++--------------
> >   1 file changed, 74 insertions(+), 53 deletions(-)
> >
> > diff --git a/perf/LuaJIT-benches/nbody.lua b/perf/LuaJIT-benches/nbody.lua
> > index e0ff8f77..f01c20a3 100644
> > --- a/perf/LuaJIT-benches/nbody.lua
> > +++ b/perf/LuaJIT-benches/nbody.lua
> > @@ -1,56 +1,12 @@

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

===================================================================
diff --git a/perf/LuaJIT-benches/nbody.lua b/perf/LuaJIT-benches/nbody.lua
index 335a43a5..4370b4d7 100644
--- a/perf/LuaJIT-benches/nbody.lua
+++ b/perf/LuaJIT-benches/nbody.lua
@@ -1,3 +1,9 @@
+-- Benchmark to check the performance of FP arithmetics.
+-- It models the orbits of Jovian planets, using the simple
+-- symplectic-integrator.
+-- For the details see:
+-- https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/nbody.html
+
 local bench = require("bench").new(arg)
 
 local sqrt = math.sqrt
===================================================================

> > +local bench = require("bench").new(arg)
> >   
> >   local sqrt = math.sqrt
> >   
> >   local PI = 3.141592653589793
> >   local SOLAR_MASS = 4 * PI * PI
> >   local DAYS_PER_YEAR = 365.24
> > -local bodies = {
> > -  { -- Sun
> > -    x = 0,
> > -    y = 0,
> > -    z = 0,
> > -    vx = 0,
> > -    vy = 0,
> > -    vz = 0,
> > -    mass = SOLAR_MASS
> > -  },
> > -  { -- Jupiter
> > -    x = 4.84143144246472090e+00,
> > -    y = -1.16032004402742839e+00,
> > -    z = -1.03622044471123109e-01,
> > -    vx = 1.66007664274403694e-03 * DAYS_PER_YEAR,
> > -    vy = 7.69901118419740425e-03 * DAYS_PER_YEAR,
> > -    vz = -6.90460016972063023e-05 * DAYS_PER_YEAR,
> > -    mass = 9.54791938424326609e-04 * SOLAR_MASS
> > -  },
> > -  { -- Saturn
> > -    x = 8.34336671824457987e+00,
> > -    y = 4.12479856412430479e+00,
> > -    z = -4.03523417114321381e-01,
> > -    vx = -2.76742510726862411e-03 * DAYS_PER_YEAR,
> > -    vy = 4.99852801234917238e-03 * DAYS_PER_YEAR,
> > -    vz = 2.30417297573763929e-05 * DAYS_PER_YEAR,
> > -    mass = 2.85885980666130812e-04 * SOLAR_MASS
> > -  },
> > -  { -- Uranus
> > -    x = 1.28943695621391310e+01,
> > -    y = -1.51111514016986312e+01,
> > -    z = -2.23307578892655734e-01,
> > -    vx = 2.96460137564761618e-03 * DAYS_PER_YEAR,
> > -    vy = 2.37847173959480950e-03 * DAYS_PER_YEAR,
> > -    vz = -2.96589568540237556e-05 * DAYS_PER_YEAR,
> > -    mass = 4.36624404335156298e-05 * SOLAR_MASS
> > -  },
> > -  { -- Neptune
> > -    x = 1.53796971148509165e+01,
> > -    y = -2.59193146099879641e+01,
> > -    z = 1.79258772950371181e-01,
> > -    vx = 2.68067772490389322e-03 * DAYS_PER_YEAR,
> > -    vy = 1.62824170038242295e-03 * DAYS_PER_YEAR,
> > -    vz = -9.51592254519715870e-05 * DAYS_PER_YEAR,
> > -    mass = 5.15138902046611451e-05 * SOLAR_MASS
> > -  }
> > -}
> > +local bodies
> > +local nbody
> >   
> >   local function advance(bodies, nbody, dt)
> >     for i=1,nbody do
> > @@ -110,10 +66,75 @@ local function offsetMomentum(b, nbody)
> >     b[1].vz = -pz / SOLAR_MASS
> >   end
> >   
> > -local N = tonumber(arg and arg[1]) or 1000
> > -local nbody = #bodies
> > +local DEFAULT_N = 5e6
> > +local N = tonumber(arg and arg[1]) or DEFAULT_N
> >   
> > -offsetMomentum(bodies, nbody)
> > -io.write( string.format("%0.9f",energy(bodies, nbody)), "\n")
> > -for i=1,N do advance(bodies, nbody, 0.01) end
> > -io.write( string.format("%0.9f",energy(bodies, nbody)), "\n")
> > +bench:add({
> > +  name = "nbody",
> > +  payload = function()
> > +    bodies = {
> > +      { -- Sun
> > +        x = 0,
> > +        y = 0,
> > +        z = 0,
> > +        vx = 0,
> > +        vy = 0,
> > +        vz = 0,
> > +        mass = SOLAR_MASS
> > +      },
> > +      { -- Jupiter
> > +        x = 4.84143144246472090e+00,
> > +        y = -1.16032004402742839e+00,
> > +        z = -1.03622044471123109e-01,
> > +        vx = 1.66007664274403694e-03 * DAYS_PER_YEAR,
> > +        vy = 7.69901118419740425e-03 * DAYS_PER_YEAR,
> > +        vz = -6.90460016972063023e-05 * DAYS_PER_YEAR,
> > +        mass = 9.54791938424326609e-04 * SOLAR_MASS
> > +      },
> > +      { -- Saturn
> > +        x = 8.34336671824457987e+00,
> > +        y = 4.12479856412430479e+00,
> > +        z = -4.03523417114321381e-01,
> > +        vx = -2.76742510726862411e-03 * DAYS_PER_YEAR,
> > +        vy = 4.99852801234917238e-03 * DAYS_PER_YEAR,
> > +        vz = 2.30417297573763929e-05 * DAYS_PER_YEAR,
> > +        mass = 2.85885980666130812e-04 * SOLAR_MASS
> > +      },
> > +      { -- Uranus
> > +        x = 1.28943695621391310e+01,
> > +        y = -1.51111514016986312e+01,
> > +        z = -2.23307578892655734e-01,
> > +        vx = 2.96460137564761618e-03 * DAYS_PER_YEAR,
> > +        vy = 2.37847173959480950e-03 * DAYS_PER_YEAR,
> > +        vz = -2.96589568540237556e-05 * DAYS_PER_YEAR,
> > +        mass = 4.36624404335156298e-05 * SOLAR_MASS
> > +      },
> > +      { -- Neptune
> > +        x = 1.53796971148509165e+01,
> > +        y = -2.59193146099879641e+01,
> > +        z = 1.79258772950371181e-01,
> > +        vx = 2.68067772490389322e-03 * DAYS_PER_YEAR,
> > +        vy = 1.62824170038242295e-03 * DAYS_PER_YEAR,
> > +        vz = -9.51592254519715870e-05 * DAYS_PER_YEAR,
> > +        mass = 5.15138902046611451e-05 * SOLAR_MASS
> > +      }
> > +    }
> > +    nbody = #bodies
> > +
> > +    offsetMomentum(bodies, nbody)
> Two `io.write()` were lost. It is intentional?

Yes, it is checked via the corresponding assertions.

> > +
> > +    assert(energy(bodies, nbody) == -0.16907516382852447179,
> > +             "Correct start energy")
> > +    for i=1,N do advance(bodies, nbody, 0.01) end
> s/1,/1, /

Fixed:
===================================================================
diff --git a/perf/LuaJIT-benches/nbody.lua b/perf/LuaJIT-benches/nbody.lua
index f01c20a3..335a43a5 100644
--- a/perf/LuaJIT-benches/nbody.lua
+++ b/perf/LuaJIT-benches/nbody.lua
@@ -125,7 +125,7 @@ bench:add({
 
     assert(energy(bodies, nbody) == -0.16907516382852447179,
              "Correct start energy")
-    for i=1,N do advance(bodies, nbody, 0.01) end
+    for _ = 1, N do advance(bodies, nbody, 0.01) end
   end,
   checker = function()
     if N == DEFAULT_N then
===================================================================

> > +  end,
> > +  checker = function()
> > +    if N == DEFAULT_N then
> > +      assert(energy(bodies, nbody) == -0.16908313397890917251,
> > +             "Correct result energy")
> > +    end
> > +    return true
> > +  end,
> > +  items = N,
> > +})
> > +
> > +bench:run_and_report()

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list