CPU: Difference between revisions
Jump to navigation
Jump to search
imported>Sam Hocevar |
imported>Sam Hocevar No edit summary |
||
| Line 40: | Line 40: | ||
| [[line|<code>line()</code>]] || <code>ceil(n/2)</code> || <code>n</code> is the number of pixels drawn; there is an additional cost of <code>1</code> if at least one pixel had to be clipped | | [[line|<code>line()</code>]] || <code>ceil(n/2)</code> || <code>n</code> is the number of pixels drawn; there is an additional cost of <code>1</code> if at least one pixel had to be clipped | ||
|- | |- | ||
| [[map|<code>map()</code>]] / [[mapdraw|<code>mapdraw()</code>]] || || | | [[map|<code>map()</code>]] / [[mapdraw|<code>mapdraw()</code>]] || <code>max(1,n*64)</code> | ||
||<code>n</code> is the number of sprites rendered; only cells that are not zero in the map are considered | |||
|- | |- | ||
| [[music|<code>music()</code>]] || <code>16</code> || no cost if no argument | | [[music|<code>music()</code>]] || <code>16</code> || no cost if no argument | ||
Revision as of 23:18, 19 December 2018
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*(A+B-1))
|
w,h = abs(x2-x1),abs(y2-y1)
|
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 |