function _draw() cls() print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") -- 19 newlines end |
costs 0.1 cpu according to ctrl-p
.
however,
function _draw() cls() print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") -- 20 newlines end |
costs 0.47 cpu. Each additional newline after that adds around 0.46 cpu usage. This happens with seperate print
calls as well. Supplying coordinates to the print
call will prevent the cpu from spiking. Note that the 20th newline is when print
will scroll the first line off the screen.
I think this is a known cost (because of the scrolling which does a full redraw)
@merwok, that can't be it because it takes 1050 loops of the first print
(with coordinates) to eat the same amount of cpu as the second print
function _draw() cls() for i = 1, 1050 do print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", 0, 0) end end |
edit: and even if you include the cls
in the loop and remove the coordinates it takes 60 loops to reach the same cpu cost
function _draw() for i = 1, 60 do cls() print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") end end |
cls()
resets the cursor position to 0,0
In both of your examples, the difference is that they don't cause the screen to scroll. It's the scrolling of the screen (necessitating redraw) that eats the CPU.
Try this:
function _draw() print("x") end |
Notice that CPU usage jumps 40+ percent once it hits the bottom and the screen is made to scroll.
Passing explicit coordinates or using cls()
regularly will prevent print()
from causing the screen to scroll.
The net CPU cost of print scrolling seems to be much lower.
Re-implemented, it is 0.11 for scrolling by sspr and 0.02 for scrolling by memcpy. (at 30 FPS).
cls() poke(0x5f36,@0x5f36|0x40) -- disable autoscroll by print function _draw() if @0x5f27>122 then ---[[ --0.02 cpu local sb=0.5*128*6 -- scroll 6px memcpy(0x6000,0x6000+sb,0x2000-sb) memset(0x8000-sb,0,sb) --[=[]] --0.11 cpu poke(0x5f54,0x60) local oldc=color(0) palt(0,false) sspr(0,6,128,122,0,0) rectfill(0,122,127,127) palt() poke(0x5f54,0x00) color(oldc) --]=] cursor(0,@0x5f27-6) end poke(0x5f26,rnd(124)) print("x") end |
[Please log in to post a comment]