Contains code pulled from Racers project.
--- /dev/null
+# Perfgraph for PICO-8
+
+This is a super simple way to get a performance graph into your PICO-8 carts.
+
+
+
+1. `#include perfgraph.lua`.
+2. Use `p_start(name)` and `p_end(name)` around the code you need to measure.
+3. Call `p_show(x,y,width)` to show a graph! (The frame times will reset after you call this.)
+
+Full example:
+
+```lua
+
+#include perfgraph.lua
+
+::l::
+
+p_start("complicated 1")
+for i=0,100 do
+ circfill(rnd()*128,rnd()*128,rnd()*100,rnd()*16)
+end
+p_end("complicated 1")
+
+p_start("complicated 2")
+for i=0,100 do
+ circ(rnd()*128,rnd()*128,rnd()*100,rnd()*16)
+end
+p_end("complicated 2")
+
+p_show(1,1,32)
+
+flip()
+
+```
+
+Have fun. You can find a demo in perfgraphdemo.p8 in this repo. If you like this then feel free to follow me on Twitter: [@btsherratt](http://twitter.com/btsherratt/).
--- /dev/null
+-- Perfgraph for PICO-8
+
+_p_perf={}
+_p_pfo={}
+
+function p_start(name,col)
+ if col==nil then
+ col=rnd()*15+1
+ end
+
+ local pp=_p_perf[name]
+ if pp==nil then
+ pp={}
+ pp.col=col
+ pp.ct=0
+ _p_perf[name]=pp
+ end
+
+ if pp.q!=true then
+ add(_p_pfo, name)
+ pp.q=true
+ end
+
+ pp.st=stat(1)
+end
+
+function p_end(name)
+ local pp=_p_perf[name]
+ if pp then
+ pp.ct+=max(stat(1)-pp.st,0)
+ end
+end
+
+function p_show(x,y,w,compact)
+ camera()
+ clip()
+ fillp()
+ for n in all(_p_pfo) do
+ local tp=_p_perf[n]
+ local pw=tp.ct*w
+ local p=flr((tp.ct*100)+0.5)
+
+ if compact then
+ rectfill(x,y,x+w,y+4,0)
+ rectfill(x,y,x+pw,y+4,tp.col)
+ print(n..":"..p.."%",x+pw+2,y,7)
+ y+=4+2
+ else
+ rectfill(x,y,x+w,y+4,0)
+ rectfill(x,y,x+pw,y+4,tp.col)
+ local lab=n..":"..p.."%"
+ rectfill(x+w+2,y,x+w+2+#lab*4,y+4,1)
+ print(lab,x+w+2,y,7)
+ y+=4+2
+ end
+
+ tp.q=false
+ tp.ct=0
+ end
+
+ _p_pfo={}
+end
\ No newline at end of file
--- /dev/null
+pico-8 cartridge // http://www.pico-8.com
+version 32
+__lua__
+#include perfgraph.lua
+
+::l::
+
+p_start("frame")
+p_start("complicated 1")
+for i=0,100 do
+ circfill(rnd()*128,rnd()*128,rnd()*100,rnd()*16)
+end
+p_end("complicated 1")
+
+p_start("complicated 2")
+for i=0,100 do
+ circ(rnd()*128,rnd()*128,rnd()*100,rnd()*16)
+end
+p_end("complicated 2")
+p_end("frame")
+
+p_show(1,1,32)
+
+flip()
+
+goto l
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000