Pico-8 keeps track of CPU usage using two values: a Lua instruction usage, and a system usage.
The function stat(1)
returns the total (Lua + system) usage for the current frame, and stat(2)
returns the system usage.
Only a few functions have a system usage, measured in ticks. There are 4194304 ticks in a second (2^22), so about 69905 ticks per frame at 60 FPS.
Functions with a system cost
Function | Ticks | Notes |
cls() |
1024 |
same cost as rectfill of same size
|
print() |
2+n*8
|
n is the number of characters in the string, even those not rendered
spaces, newlines, and double-width glyphs each count as one character |
spr() |
n | n is the number of pixels drawn, including transparent pixels (width × height of the sprite rectangle)
cost is 0 if first argument is outside the [0, 255] range |
sspr() |
n
|
n is the number of pixels drawn, including transparent pixels (width × height of the destination rectangle)
|
rect() |
max(1,2*ceil(a/4)) + max(0,2*ceil(b/2-1))
|
Where:
|
rectfill() |
max(1,flr(n/16)) |
n is the number of pixels drawn (width × height)
|
circ() |
?
|
|
circfill() |
?
|
|
line() |
ceil(n/2) |
n is the number of pixels drawn; there is an additional cost of 1 if at least one pixel had to be clipped
|
map() / mapdraw() |
max(1,n*64)
|
n is the number of sprites rendered; only cells that are not zero in the map are considered
|
music() |
16 |
no cost if no argument |
sfx() |
16 |
no cost if no argument |
memcpy() |
n+1
|
n is the number of bytes copied
|
memset() |
max(1,ceil(n/2))
|
n is the number of bytes set
|
reload() |
max(1,n*8)
|
n is the number of bytes reloaded
|
btn() |
4 |
no cost if no argument |
btnp() |
4 |
no cost if no argument |
rnd() |
4 |
|
sqrt() |
24 |
only 16 if argument is zero
|
stat() |
16 |