mlua-luau-scheduler/examples/lua/lots_of_threads.luau
Filip Tibell 588fc46807
Refactor runtime and callbacks
* Improved ergonomics and flexibility for crate consumers
* Simplified callback mechanism for errors
* Factor out runtime thread queues into proper structs
* Misc performance improvements - approx 20% faster scheduler
2024-01-24 19:50:25 +01:00

29 lines
601 B
Lua

--!nocheck
--!nolint UnknownGlobal
local NUM_BATCHES = 10
local NUM_THREADS = 10_000
print(`Spawning {NUM_BATCHES * NUM_THREADS} threads split into {NUM_BATCHES} batches\n`)
local before = os.clock()
for i = 1, NUM_BATCHES do
print(`Batch {i} of {NUM_BATCHES}`)
local thread = coroutine.running()
local counter = 0
for j = 1, NUM_THREADS do
spawn(function()
sleep()
counter += 1
if counter == NUM_THREADS then
spawn(thread)
end
end)
end
coroutine.yield()
end
local after = os.clock()
print(`\nSpawned {NUM_BATCHES * NUM_THREADS} sleeping threads in {after - before}s`)