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

Sergey Bronnikov sergeyb at tarantool.org
Mon Nov 17 11:36:20 MSK 2025


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.
> ---
>
> I'm not sure that amount of permutations is the correct items count.
> Have you any other suggestions?
>
>   perf/LuaJIT-benches/fannkuch.lua | 37 +++++++++++++++++++++++++++++---
>   1 file changed, 34 insertions(+), 3 deletions(-)
>
> diff --git a/perf/LuaJIT-benches/fannkuch.lua b/perf/LuaJIT-benches/fannkuch.lua
> index 2a4cd426..c963c66f 100644
> --- a/perf/LuaJIT-benches/fannkuch.lua
> +++ b/perf/LuaJIT-benches/fannkuch.lua

I'm highly recommend adding description to benchmarks.

At least to the tests from "benchmarks game" suite.

You can use descriptions from the [1] and [2].

1. https://benchmarksgame-team.pages.debian.net/benchmarksgame/

2. 
https://en.wikipedia.org/wiki/The_Computer_Language_Benchmarks_Game#Benchmark_programs


> @@ -1,3 +1,4 @@
> +local bench = require("bench").new(arg)
>   
>   local function fannkuch(n)
>     local p, q, s, odd, check, maxflips = {}, {}, {}, true, 0, 0
> @@ -6,7 +7,7 @@ local function fannkuch(n)
>       -- Print max. 30 permutations.
>       if check < 30 then
>         if not p[n] then return maxflips end	-- Catch n = 0, 1, 2.
> -      io.write(unpack(p)); io.write("\n")
> +      -- io.write(unpack(p)); io.write("\n")
isn't better to remove at all?
>         check = check + 1
>       end
>       -- Copy and flip.
> @@ -46,5 +47,35 @@ local function fannkuch(n)
>     until false
>   end
>   
> -local n = tonumber(arg and arg[1]) or 1
> -io.write("Pfannkuchen(", n, ") = ", fannkuch(n), "\n")
> +local n = tonumber(arg and arg[1]) or 11
> +
> +-- Precomputed numbers taken from:
please add description of the paper as well: "Performing Lisp Analysis 
of the FANNKUCH Benchmark"
> +--https://dl.acm.org/doi/pdf/10.1145/382109.382124
> +local FANNKUCH = { 0, 1, 2, 4, 7, 10, 16, 22, 30, 38, 51, 65, 80 }
> +
> +local function factorial(n)
> +  local fact = 1
> +  for i = 2, n do
> +    fact = fact * i
> +  end
> +  return fact
> +end
> +
> +bench:add({
> +  name = "fannkuch",
> +  payload = function()
> +    return fannkuch(n)
> +  end,
> +  checker = function(res)
> +    if n > #FANNKUCH then
> +      -- Not precomputed, so can't check.
> +      return true
> +    else
> +      return res == FANNKUCH[n]
> +    end
> +  end,
> +  -- Assume that we count permutations here.
> +  items = factorial(n),
> +})
> +
> +bench:run_and_report()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20251117/78dd07a3/attachment.htm>


More information about the Tarantool-patches mailing list