Skip to content

Instantly share code, notes, and snippets.

@MCJack123
Created July 7, 2020 23:41
Show Gist options
  • Save MCJack123/4166124e44c02208eb0bd6ca47f38bad to your computer and use it in GitHub Desktop.
Save MCJack123/4166124e44c02208eb0bd6ca47f38bad to your computer and use it in GitHub Desktop.
CraftOS-PC rendering stress tests for character & graphics modes
local w, h = term.getSize()
local canBenchmark = term.benchmark ~= nil
local count = 0
local start = os.epoch "utc"
if canBenchmark then term.benchmark() end
pcall(function()
while true do
term.setCursorPos(math.random(1, w), math.random(1, h))
term.setBackgroundColor(2^math.random(0, 15))
term.setTextColor(2^math.random(0, 15))
term.write(string.char(math.random(0, 255)))
count = count + 1
end
end)
local frames = canBenchmark and term.benchmark() or 0
local time = os.epoch "utc" - start
term.setCursorPos(1, 1)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
if canBenchmark then print("Rendered " .. frames .. " frames in " .. time .. " ms (" .. (frames / (time / 1000)) .. " fps)") end
print("Drew " .. count .. " characters (" .. (count / (time / 1000)) .. " cps)")
term.setGraphicsMode(2)
local w, h = term.getSize()
local canBenchmark = term.benchmark ~= nil
w, h = w*6-1, h*9-1
for i = 0, 255 do term.setPaletteColor(i, 7 / bit32.rshift(bit32.band(i, 0xE0), 5), 7 / bit32.rshift(bit32.band(i, 0x1C), 2), 3 / bit32.band(i, 3)) end
local count = 0
local start = os.epoch "utc"
if canBenchmark then term.benchmark() end
pcall(function()
while true do
term.setPixel(math.random(0, w), math.random(0, h), math.random(0, 255))
count = count + 1
end
end)
local frames = canBenchmark and term.benchmark() or 0
local time = os.epoch "utc" - start
term.clear()
for i = 0, 15 do term.setPaletteColor(i, term.nativePaletteColor(2^i)) end
term.setGraphicsMode(0)
if canBenchmark then print("Rendered " .. frames .. " frames in " .. time .. " ms (" .. (frames / (time / 1000)) .. " fps)") end
print("Drew " .. count .. " pixels (" .. (count / (time / 1000)) .. " pps)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment