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/recursive-fib.lua | 28 +++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/perf/LuaJIT-benches/recursive-fib.lua b/perf/LuaJIT-benches/recursive-fib.lua
index ef9950de..99af3f9e 100644
--- a/perf/LuaJIT-benches/recursive-fib.lua
+++ b/perf/LuaJIT-benches/recursive-fib.lua
@@ -1,7 +1,31 @@
+local bench = require("bench").new(arg)
+
local function fib(n)
if n < 2 then return 1 end
return fib(n-2) + fib(n-1)
end
-local n = tonumber(arg[1]) or 10
-io.write(string.format("Fib(%d): %d\n", n, fib(n)))
debug print was lost, is it intentional?
Why 40?+local n = tonumber(arg[1]) or 40
+
+local benchmark
+benchmark = {
+ name = "recursive_fib",
+ checker = function(res)
+ local km1, k = 1, 1
+ for i = 2, n do
+ local tmp = k + km1
+ km1 = k
+ k = tmp
+ end
+ return k == res
+ end,
+ payload = function()
+ local res = fib(n)
+ -- Number of calls.
+ benchmark.items = res * 2 - 1
+ return res
+ end,
+}
+
+bench:add(benchmark)
+bench:run_and_report()