From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 6AA74158B38C; Mon, 17 Nov 2025 16:30:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6AA74158B38C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1763386213; bh=7uhrQoSFD6L8islnTGU2rNbXNP2eWNi94bJJSrbqDx8=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=drL+fCwn+Bked3IFchfUjQ9ac9+MUbkS3AmlixTtqrhq2sdGTFtBzRK7ZCPkPAHO5 ujtYZ5jE06t991FTC4BzdUV5skewKxIXUMwEQFAsQ69ADxCE8+XVpqmwo0zWG356JL s5qMTdgHY9pjFd5M+xhRiDF2Guwleser2z+Y3eHY= Received: from send105.i.mail.ru (send105.i.mail.ru [89.221.237.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 20CEB15DEA90 for ; Mon, 17 Nov 2025 16:26:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 20CEB15DEA90 Received: by exim-smtp-77df68b9cf-f5597 with esmtpa (envelope-from ) id 1vKzFU-00000000EVi-0qkj; Mon, 17 Nov 2025 16:26:28 +0300 Content-Type: multipart/alternative; boundary="------------fyxBjDR0ezeGnAWNbsNZFe8M" Message-ID: <29e184ea-8946-42e0-a594-dcfa74ac9792@tarantool.org> Date: Mon, 17 Nov 2025 16:26:27 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org References: <771ce40700f63e508869a55a973d8f852ee93a06.1761301736.git.skaplun@tarantool.org> In-Reply-To: <771ce40700f63e508869a55a973d8f852ee93a06.1761301736.git.skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9110BAFCBE6BD1D1605FE00F9132C87FE67EE782B408ED083182A05F538085040B081ADF6BB0CB00E3DE06ABAFEAF6705E902AE874980734B3C1CBB97E487F8EEBC0FEE398BF55443 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D78D3A378738F99DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566D0BE23D09F2BEA50A3EC40626640EC855D418E71EBF5838D2C705570A17CFF6B389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C07E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B64854413538E1713FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C224958C1606C78F2434E76E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B6A4E49BB0F3BA1413AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E73525A4AB119743A3B3C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A56A9B719274A6C8F25002B1117B3ED696D5BFC880755126CC108A05421C070DB8823CB91A9FED034534781492E4B8EEAD47A3109F1ACFD409BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF645ECFEF0F8794090225BC8AF8CF22B79F1ED0467B41EC067CE0DFC1197437FE327C9FD717F33718DD12B02666E49356857C4A36A7D30FED436C6D7D7CA0006D420C834972AFF6FA111DC66A97D0BFE2913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVfFX+FmbwDW1FGR0CjKsHsI= X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B5942A7702C785423E53DE06ABAFEAF6705E902AE874980734BB7CBEF92542CD7C8795FA72BAB74744FC77752E0C033A69EA16A481184E8BB1C9B38E6EA4F046BE03A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 luajit 17/41] perf: adjust nbody in LuaJIT-benches X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------fyxBjDR0ezeGnAWNbsNZFe8M Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 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 @@ > +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? > + > + assert(energy(bodies, nbody) == -0.16907516382852447179, > + "Correct start energy") > + for i=1,N do advance(bodies, nbody, 0.01) end s/1,/1, / > + 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() --------------fyxBjDR0ezeGnAWNbsNZFe8M Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

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 @@
+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?
+
+    assert(energy(bodies, nbody) == -0.16907516382852447179,
+             "Correct start energy")
+    for i=1,N do advance(bodies, nbody, 0.01) end
s/1,/1, /
+  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()
--------------fyxBjDR0ezeGnAWNbsNZFe8M--