[Tarantool-patches] [PATCH v1 luajit 12/41] perf: adjust life in LuaJIT-benches
Sergey Bronnikov
sergeyb at tarantool.org
Mon Nov 17 11:35:21 MSK 2025
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 output is redirected to /dev/null. The checker tests the result
> after the exact amount of iterations for the fixed field (as it is
> declared in the original benchmark).
> ---
> perf/LuaJIT-benches/life.lua | 79 +++++++++++++++++++++++++++++++++++-
> 1 file changed, 78 insertions(+), 1 deletion(-)
>
> diff --git a/perf/LuaJIT-benches/life.lua b/perf/LuaJIT-benches/life.lua
> index 911d9fe1..d0e4dc98 100644
> --- a/perf/LuaJIT-benches/life.lua
> +++ b/perf/LuaJIT-benches/life.lua
> @@ -3,6 +3,8 @@
> -- modified to use ANSI terminal escape sequences
> -- modified to use for instead of while
>
> +local bench = require('bench').new(arg)
> +
> local write=io.write
>
> ALIVE="�" DEAD="�"
We usually use ascii only symbols. Should we replace with ascii-only
alternative?
> @@ -106,6 +108,81 @@ function LIFE(w,h)
> if gen>2000 then break end
> --delay() -- no delay
dead code
> end
> + return thisgen
> end
>
> -LIFE(40,20)
> +-- Result of the LIFE(40, 20) after 2000 generations.
> +--[[
> +----------------------------------------
> +----------------------------------------
> +--OO--------------------------O---------
> +-OO--------------------------O-O--------
> +---O--------------------------O---------
> +----------------------------------------
> +----------------------------------------
> +----------------------------------------
> +----------------------------------------
> +----------------------------------------
> +----------------------------------------
> +----------------------------------------
> +---O------------------------------------
> +--O-O-----------------------------------
> +--O-O-----------------------------------
> +---O------------------------------------
> +----------------------------------------
> +-------OO-------------------------------
> +-------OO-------------------------------
> +----------------------------------------
> +]]
> +
> +local function check_life(thisgen, w, h)
> + local expected_cells = ARRAY2D(w, h)
> + for y = 1, h do
> + for x = 1, w do
> + expected_cells[y][x] = false
> + end
> + end
> + local alive_cells = {
> + {3, 3}, {3, 4}, {3, 31},
> + {4, 2}, {4, 3}, {4, 30}, {4, 32},
> + {5, 4}, {5, 31},
> + {13, 4},
> + {14, 3}, {14, 5},
> + {15, 3}, {15, 5},
> + {16, 4},
> + {18, 8}, {18, 9},
> + {19, 8}, {19, 9},
> + }
> + for _, cell in ipairs(alive_cells) do
> + local y, x = cell[1], cell[2]
> + expected_cells[y][x] = true
> + end
> + for y = 1, h do
> + for x = 1, w do
> + assert(thisgen[y][x] > 0 == expected_cells[y][x],
> + ('Incorrect value for cell (%d, %d)'):format(x, y))
> + end
> + end
> + return true
> +end
> +
> +local stdout = io.output()
> +
> +bench:add({
> + name = 'life',
> + setup = function()
> + io.output('/dev/null')
> + end,
> + payload = function()
> + return LIFE(40, 20)
> + end,
> + teardown = function()
> + io.output(stdout)
> + end,
> + checker = function(res)
> + return check_life(res, 40, 20)
> + end,
> + items = 2000 * 40 * 20,
> +})
> +
> +bench:run_and_report()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20251117/d0ce0f36/attachment-0001.htm>
More information about the Tarantool-patches
mailing list