Hi, Sergey,
thanks for the patch! See my comments.
Sergey
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/partialsums.lua | 69 ++++++++++++++++++-----------
1 file changed, 42 insertions(+), 27 deletions(-)
diff --git a/perf/LuaJIT-benches/partialsums.lua b/perf/LuaJIT-benches/partialsums.lua
index 46bb9da3..ab24b30a 100644
--- a/perf/LuaJIT-benches/partialsums.lua
+++ b/perf/LuaJIT-benches/partialsums.lua
@@ -1,29 +1,44 @@
+local bench = require("bench").new(arg)
-local n = tonumber(arg[1])
-local function pr(fmt, x) io.write(string.format(fmt, x)) end
+local DEFAULT_N = 1e7
+local n = tonumber(arg[1]) or DEFAULT_N
Why 1e7 is default?
-local a1, a2, a3, a4, a5, a6, a7, a8, a9, alt = 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
-local sqrt, sin, cos = math.sqrt, math.sin, math.cos
-for k=1,n do
- local k2, sk, ck = k*k, sin(k), cos(k)
- local k3 = k2*k
- a1 = a1 + (2/3)^k
- a2 = a2 + 1/sqrt(k)
- a3 = a3 + 1/(k2+k)
- a4 = a4 + 1/(k3*sk*sk)
- a5 = a5 + 1/(k3*ck*ck)
- a6 = a6 + 1/k
- a7 = a7 + 1/k2
- a8 = a8 + alt/k
- a9 = a9 + alt/(k+k-1)
- alt = -alt
-end
-pr("%.9f\t(2/3)^k\n", a1)
-pr("%.9f\tk^-0.5\n", a2)
-pr("%.9f\t1/k(k+1)\n", a3)
-pr("%.9f\tFlint Hills\n", a4)
-pr("%.9f\tCookson Hills\n", a5)
-pr("%.9f\tHarmonic\n", a6)
-pr("%.9f\tRiemann Zeta\n", a7)
-pr("%.9f\tAlternating Harmonic\n", a8)
-pr("%.9f\tGregory\n", a9)
debug prints were lost, is it intentional?
In a previous benches debug prints were left, but suppressed.
Also I propose to use the same printf function in all benches for consistency.
+bench:add({
+ name = "partialsums",
+ payload = function()
+ local a1, a2, a3, a4, a5, a6, a7, a8, a9, alt = 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
+ local sqrt, sin, cos = math.sqrt, math.sin, math.cos
+ for k=1,n do
please add more whitespaces, here and below
+ local k2, sk, ck = k*k, sin(k), cos(k)
+ local k3 = k2*k
+ a1 = a1 + (2/3)^k
+ a2 = a2 + 1/sqrt(k)
+ a3 = a3 + 1/(k2+k)
+ a4 = a4 + 1/(k3*sk*sk)
+ a5 = a5 + 1/(k3*ck*ck)
+ a6 = a6 + 1/k
+ a7 = a7 + 1/k2
+ a8 = a8 + alt/k
+ a9 = a9 + alt/(k+k-1)
+ alt = -alt
+ end
+ return {a1, a2, a3, a4, a5, a6, a7, a8, a9}
+ end,
+ checker = function(a)
+ if n == DEFAULT_N then
+ assert(a[1] == 2.99999999999999866773)
+ assert(a[2] == 6323.09512394020111969439)
+ assert(a[3] == 0.99999989999981531152)
+ assert(a[4] == 30.31454593111029183206)
+ assert(a[5] == 42.99523427973661426904)
+ assert(a[6] == 16.69531136585727182364)
+ assert(a[7] == 1.64493396684725956547)
+ assert(a[8] == 0.69314713056010635039)
+ assert(a[9] == 0.78539813839744787582)
+ end
+ return true
+ end,
+ items = n,
+})
+
+bench:run_and_report()