From 20e551590b4491dade12191caf94411e7ec67dd9 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 4 Jun 2024 14:31:53 +0200 Subject: Refactored keeper implementation of linda:get() --- tests/basic.lua | 23 +++++++++++++++++++++-- tests/linda_perf.lua | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/basic.lua b/tests/basic.lua index fff19ed..ecd93fc 100644 --- a/tests/basic.lua +++ b/tests/basic.lua @@ -249,7 +249,26 @@ assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications") -- ["->"] master -> slave -- ["<-"] slave <- master -local function PEEK() return linda:get("<-") end +WR "test linda:get/set..." +linda:set("<->", "x", "y", "z") +local x,y,z = linda:get("<->", 1) +assert(x == "x" and y == nil and z == nil) +local x,y,z = linda:get("<->", 2) +assert(x == "x" and y == "y" and z == nil) +local x,y,z = linda:get("<->", 3) +assert(x == "x" and y == "y" and z == "z") +local x,y,z,w = linda:get("<->", 4) +assert(x == "x" and y == "y" and z == "z" and w == nil) +local k, x = linda:receive("<->") +assert(k == "<->" and x == "x") +local k,y,z = linda:receive(linda.batched, "<->", 2) +assert(k == "<->" and y == "y" and z == "z") +linda:set("<->") +local x,y,z,w = linda:get("<->", 4) +assert(x == nil and y == nil and z == nil and w == nil) +WR "ok\n" + +local function PEEK(...) return linda:get("<-", ...) end local function SEND(...) linda:send("->", ...) end local function RECEIVE() local k,v = linda:receive(1, "<-") return v end @@ -259,7 +278,7 @@ SEND(1); WR("main ", "1 sent\n") SEND(2); WR("main ", "2 sent\n") SEND(3); WR("main ", "3 sent\n") SEND(setmetatable({"should be ignored"},{__lanesignore=true})); WR("main ", "__lanesignore table sent\n") -for i=1,100 do +for i=1,40 do WR "." SLEEP(0.0001) assert(PEEK() == nil) -- nothing coming in, yet diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index a50e906..4d35380 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua @@ -62,12 +62,13 @@ local lane_gobbler_gen = lanes.gen( "*", {priority = 3}, gobbler) local function ziva( preloop, loop, batch) -- prefill the linda a bit to increase fifo stress local top = math.max( preloop, loop) - local l, lane = lanes.linda() + local l = lanes.linda() local t1 = lanes.now_secs() for i = 1, preloop do l:send( "key", i) end print( "stored " .. l:count( "key") .. " items in the linda before starting consumer lane") + local lane if batch > 0 then if l.batched then lane = lane_gobbler_gen( l, top, batch) @@ -102,6 +103,28 @@ local function ziva( preloop, loop, batch) return lanes.now_secs() - t1 end +-- ################################################################################################# +do + print "############################################ tests get/set" + -- linda:get throughput + local l = lanes.linda("get/set") + local batch = {} + for i = 1,1000 do + table.insert(batch, i) + end + for _,size in ipairs{1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 } do + l:set("<->", table_unpack(batch)) + local count = 20000000//size + print("START", "get("..size..") " .. count, " times") + local t1 = lanes.now_secs() + for i = 1, 2000000/math.sqrt(size) do + l:get("<->", size) + end + print("DURATION = " .. lanes.now_secs() - t1 .. "\n") + end +end + +do return end -- ################################################################################################# TEST1 = TEST1 or 1000 @@ -118,8 +141,9 @@ local tests1 = { PREFILL1, FILL1, 8}, { PREFILL1, FILL1, 13}, { PREFILL1, FILL1, 21}, - { PREFILL1, FILL1, 44}, - { PREFILL1, FILL1, 65}, + { PREFILL1, FILL1, 34}, + { PREFILL1, FILL1, 55}, + { PREFILL1, FILL1, 89}, } print "############################################ tests #1" for i, v in ipairs( tests1) do @@ -194,8 +218,9 @@ local tests2 = { PREFILL2, FILL2, 8}, { PREFILL2, FILL2, 13}, { PREFILL2, FILL2, 21}, - { PREFILL2, FILL2, 44}, - { PREFILL2, FILL2, 65}, + { PREFILL2, FILL2, 34}, + { PREFILL2, FILL2, 55}, + { PREFILL2, FILL2, 89}, } print "############################################ tests #2" -- cgit v1.2.3-55-g6feb