[Tarantool-patches] [PATCH v1 luajit 07/41] perf: adjust coroutine-ring in LuaJIT-benches
Sergey Kaplun
skaplun at tarantool.org
Fri Oct 24 13:50:11 MSK 2025
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/coroutine-ring.lua | 45 ++++++++++++++++----------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/perf/LuaJIT-benches/coroutine-ring.lua b/perf/LuaJIT-benches/coroutine-ring.lua
index 1e8c5ef6..1b86a5ba 100644
--- a/perf/LuaJIT-benches/coroutine-ring.lua
+++ b/perf/LuaJIT-benches/coroutine-ring.lua
@@ -1,3 +1,5 @@
+local bench = require("bench").new(arg)
+
-- The Computer Language Benchmarks Game
-- http://shootout.alioth.debian.org/
-- contributed by Sam Roberts
@@ -7,7 +9,6 @@ local n = tonumber(arg and arg[1]) or 2e7
-- fixed size pool
local poolsize = 503
-local threads = {}
-- cache these to avoid global environment lookups
local create = coroutine.create
@@ -15,7 +16,6 @@ local resume = coroutine.resume
local yield = coroutine.yield
local id = 1
-local token = 0
local ok
local body = function(token)
@@ -24,19 +24,30 @@ local body = function(token)
end
end
--- create all threads
-for id = 1, poolsize do
- threads[id] = create(body)
-end
-
--- send the token
-repeat
- if id == poolsize then
- id = 1
- else
- id = id + 1
- end
- ok, token = resume(threads[id], token)
-until token == n
+bench:add({
+ name = "coroutine_ring",
+ payload = function()
+ local token = 0
+ -- create all threads
+ local threads = {}
+ for id = 1, poolsize do
+ threads[id] = create(body)
+ end
+
+ -- send the token
+ repeat
+ if id == poolsize then
+ id = 1
+ else
+ id = id + 1
+ end
+ ok, token = resume(threads[id], token)
+ until token == n
+ return id
+ end,
+ checker = function(id) return id == (n % poolsize + 1) end,
+ items = n,
+})
+
+bench:run_and_report()
-io.write(id, "\n")
--
2.51.0
More information about the Tarantool-patches
mailing list