Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local port = 65535
- local rednetFormat = true
- local mod = peripheral.wrap("back")
- mod.open(port)
- local tCount = 100
- local timeout = 0.05
- local total = 0
- local rTotal = 0
- local start = os.clock()
- local function der(num)
- while true do
- -- coroutine.yield()
- for i = 1, 65535 do
- coroutine.yield()
- -- term.setCursorPos(1, num)
- -- term.clearLine()
- total = total + 1
- rTotal = rTotal + 1
- if num > tCount - 49 then
- print("Thread: " .. num .. " | Id: " .. i)
- end
- if rednetFormat == true then
- local nMessageID = math.random( 1, 2147483647 )
- local tMessage = {
- nMessageID = nMessageID,
- nRecipient = port,
- message = "TOTAL: " .. rTotal
- }
- mod.transmit(port, i, tMessage)
- else
- mod.transmit(port, i, "TOTAL: " .. rTotal)
- end
- end
- end
- end
- local threads = {}
- for i = 1, tCount do
- table.insert(threads, coroutine.create(function() der(i) end))
- end
- local function F1()
- while true do
- -- sleep(0.1)
- term.clear()
- term.setCursorPos(1, 1)
- for i,v in pairs(threads) do
- coroutine.resume(v)
- end
- print("\n\n")
- term.setCursorPos(1, 17)
- write("Press 'up' or 'down' to control thread count")
- term.setCursorPos(1, 18)
- -- term.clearLine()
- local cur = os.clock() - start
- write("Maximum Speed: " .. tCount / timeout)
- term.setCursorPos(1, 19)
- -- term.clearLine()
- write("Speed: " .. total / cur .. " per second.")
- if cur > 1 then
- start = os.clock()
- total = 0
- end
- sleep(timeout)
- end
- end
- local function F2()
- while true do
- local event, key = os.pullEvent("key")
- if key == 200 then
- table.insert(threads, coroutine.create(function() der(tCount) end))
- -- total = 0
- -- start = os.clock()
- tCount = tCount + 1
- elseif key == 208 then
- if #threads > 0 then
- threads[#threads] = nil
- -- total = 0
- tCount = tCount - 1
- -- start = os.clock()
- end
- end
- end
- end
- parallel.waitForAny(F1, F2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement