PICO-8 Wiki
mNo edit summary
Tag: Visual edit
(New measurements.)
Tag: Visual edit
Line 3: Line 3:
 
== Functions with a system cost ==
 
== Functions with a system cost ==
   
Only a handful of functions have a system cost:
+
Only a handful of functions have a system cost, measured in ticks. There are 4194304 ticks in a second (2^22), so about 69905 ticks in a frame at 60 FPS.
   
 
{|
 
{|
| Function || Cost
+
| Function || Ticks || Notes
 
|-
 
|-
| [[cls|<code>cls</code>]] ||
+
| [[cls|<code>cls</code>]] || <code>1024</code> || same cost as [[rectfill|<code>rectfill</code>]] of same size
 
|-
 
|-
| [[print|<code>print</code>]] ||
+
| [[print|<code>print</code>]] || ||
 
|-
 
|-
| [[spr|<code>spr</code>]] ||
+
| [[spr|<code>spr</code>]] || ||
 
|-
 
|-
| [[sspr|<code>sspr</code>]] ||
+
| [[sspr|<code>sspr</code>]] || ||
 
|-
 
|-
| [[rect|<code>rect</code>]] ||
+
| [[rect|<code>rect</code>]] || ||
 
|-
 
|-
| [[rectfill|<code>rectfill</code>]] ||
+
| [[rectfill|<code>rectfill</code>]] || <code>max(1,flr(n/16))</code> || <code>n</code> is the number of pixels drawn (width × height)
 
|-
 
|-
| [[circ|<code>circ</code>]] ||
+
| [[circ|<code>circ</code>]] || ||
 
|-
 
|-
| [[circfill|<code>circfill</code>]] ||
+
| [[circfill|<code>circfill</code>]] || ||
 
|-
 
|-
  +
| [[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>]] ||
 
 
|-
 
|-
| [[map|<code>map</code>]] / [[mapdraw|<code>mapdraw</code>]] ||
+
| [[map|<code>map</code>]] / [[mapdraw|<code>mapdraw</code>]] || ||
 
|-
 
|-
| [[music|<code>music</code>]] ||
+
| [[music|<code>music</code>]] || <code>16</code> || no cost if no argument
 
|-
 
|-
| [[sfx|<code>sfx</code>]] ||
+
| [[sfx|<code>sfx</code>]] || <code>16</code> || no cost if no argument
 
|-
 
|-
| [[memcpy|<code>memcpy</code>]] ||
+
| [[memcpy|<code>memcpy</code>]] || ||
 
|-
 
|-
| [[memset|<code>memset</code>]] ||
+
| [[memset|<code>memset</code>]] || ||
 
|-
 
|-
| [[reload|<code>reload</code>]] ||
+
| [[reload|<code>reload</code>]] || ||
 
|-
 
|-
| [[rnd|<code>rnd</code>]] ||
+
| [[btn|<code>btn</code>]] || <code>4</code> || no cost if no argument
 
|-
 
|-
| [[sqrt|<code>sqrt</code>]] ||
+
| [[btnp|<code>btnp</code>]] || <code>4</code> || no cost if no argument
 
|-
 
|-
| [[btn|<code>btn</code>]] ||
+
| [[rnd|<code>rnd</code>]] || <code>4</code> ||
 
|-
 
|-
| [[btnp|<code>btnp</code>]] ||
+
| [[sqrt|<code>sqrt</code>]] || <code>24</code> || only <code>16</code> if argument is zero
 
|-
 
|-
| [[stat|<code>stat</code>]] ||
+
| [[stat|<code>stat</code>]] || <code>16</code> ||
 
|}
 
|}

Revision as of 20:23, 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) return the sum of these values, and stat(2) returns the CPU usage.

Functions with a system cost

Only a handful of functions have a system cost, measured in ticks. There are 4194304 ticks in a second (2^22), so about 69905 ticks in a frame at 60 FPS.

Function Ticks Notes
cls 1024 same cost as rectfill of same size
print
spr
sspr
rect
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
music 16 no cost if no argument
sfx 16 no cost if no argument
memcpy
memset
reload
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