From: Ben Sherratt Date: Mon, 5 Jan 2026 00:34:37 +0000 (+0000) Subject: Changed to a cart X-Git-Url: https://git.bts.cx/p8-perfgraph.git/commitdiff_plain/d07b3595627e0868f7d7b84bcf70b69f5f97502d?ds=inline;hp=b1218829b31952667ccf3e52b27fe09cc384a373 Changed to a cart * Bundled in demo * Switched to use outlined text --- diff --git a/README.md b/README.md index d74eee7..98c305f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a super simple way to get a performance graph into your PICO-8 carts. ![See it in action!](demo1.gif) -1. `#include perfgraph.lua`. +1. `#include perfgraph.p8:1`. 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.) @@ -12,7 +12,7 @@ Full example: ```lua -#include perfgraph.lua +#include perfgraph.p8:1 ::l:: @@ -38,4 +38,4 @@ goto l ``` -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/). +Have fun! diff --git a/perfgraph.lua b/perfgraph.lua deleted file mode 100644 index c7faee1..0000000 --- a/perfgraph.lua +++ /dev/null @@ -1,62 +0,0 @@ --- 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 diff --git a/perfgraph.p8 b/perfgraph.p8 new file mode 100644 index 0000000..54c76c6 --- /dev/null +++ b/perfgraph.p8 @@ -0,0 +1,242 @@ +pico-8 cartridge // http://www.pico-8.com +version 43 +__lua__ +-- perfgraph for pico-8 +-- simple performance graphs + +--[[ + +this is a super simple way + to get a performance graph + into your pico-8 carts. + +1. #include perfgraph.p8:1. +2. use 'p_start' and 'p_end' + around the code you need + to measure. +3. call 'p_show' + to show a graph! + (the frame times will + reset after you + call this.) + +see full example on tab 2! + +]] + +-->8 +-- ⧗ implementation ⧗ -- + +_p_perf={} + +function p_start(name,col) + local idx=_p_perf[name] + if(idx==nil)idx=#_p_perf+1 + _p_perf[name]=idx + if(_p_perf[idx]==nil)_p_perf[idx]={name=name,col=col or idx%15+1} + local p=_p_perf[idx] + p.ct=p.ct or 0 + p.st=stat(1) +end + +function p_end(name) + assert(_p_perf[name]) + local p=_p_perf[_p_perf[name]] + p.ct+=max(stat(1)-p.st,0) +end + +function p_show(x,y,w,compact) + local cx,cy=camera() + clip() + fillp() + + for idx,tp in ipairs(_p_perf) do + if tp.ct then + rectfill(x,y,x+w,y+4,0) + rectfill(x,y,x+tp.ct*w,y+4,tp.col) + ?"\^o0ff"..tp.name..":"..flr((tp.ct*100)+0.5).."%",x+w+4,y,7 + y+=6 + end + tp.ct=nil + end + + camera(cx,cy) +end + +-->8 +-- ♥ demo! ♥ -- + +local m=10/100 + +::l:: + +p_start("frame") + +cls() + +f=10 +fl=true +for i=0,-5000,-10 do + p_start("circle calculation") + local h=10 + local z=i+time()*20 + local x=cos(i/45)*8 + local y=cos(i/100)*8 + local hi=h*m*z + local c=7 + if(fl)c=0 + fl=not fl + p_end("circle calculation") + + p_start("circle draw") + circfill(64+x,64+y,hi,c) + p_end("circle draw") +end + + + +p_end("frame") + +p_show(1,1,32) + +flip() + +goto l + +__gfx__ +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +__label__ +00007777777777777777777777777777777700000000000000000000000000000000000000000000000000000077777777777777777770000000000000000000 +02222222222222222222222200000000007707770777077707770777000007000777070700000000000000000000077777777777777777000000000000000000 +02222222222222222222222200000000007707000707070707770700007007000707000700000000000000000000000777777777777777700000000000000000 +02222222222222222222222200000000000007700770077707070770000007770777007000000000000000000000000007777777777777770000000000000000 +72222222222222222222222200000000000007000707070707070700007007070007070000000000000000000000000000077777777777777000000000000000 +72222222222222222222222200000000000007000707070707070777000007770007070700000000000000000000000000000777777777777700000000000000 +77777777777777777777777777777000000000000000000000000000000000000000000000000000000000000000000000000000000077770000000000000000 +73333330000000000000000000000000000000770777077700770700077700000077077707000077070707000777077707770077077000000770077707070000 +73333330000000000000000000000000000007000070070707000700070000000700070707000700070707000707007000700707070700700070070700070000 +73333330000000000000000000000000000007000070077007000700077000000700077707000700070707000777007000700707070700007070077700700000 +73333330000000000000000000000000000007000070070707000700070000000700070707000700070707000707007000700707070700700070070707000000 +73333330000000000000000000000000000000770777070700770777077707770077070707770077007707770707007007770770070700000777077707070000 +77777777777777777777000000000000000000000000000000000000000007770000000000000000000000000000000000000000000000070000000000000000 +74444444000000000000000000000000000000770777077700770707077707770770077707770707000007770770070700000000000000007777777770000000 +74444444000000000000000000000000000007000070070707000707070007770707070707070707007000070070000700000000000000000777777777000000 +74444444000000000000000000000000000007000070077007070707077077770707077007770707000007770070007007000000000000000077777777000000 +74444444000000000000000000000000000007000070070707000700070007770707070707070777007007000070070007770000000000000007777777700000 +74444444000000000000000000000000000000770777070700770777077707770777070707070777000007770777070707777700000000000000777777770000 +77777777777777000000000000000000000000000000000000000000000007770000000000000000077700000000000007777770000000000000077777770000 +77777777777770000000000000000000000000007777777777777777777777777777777777777777777777777777777777777777700000000000007777777000 +77777777777700000000000000000000000000077777777777777777777777777777777777777777777777777777777777777777770000000000000777777700 +77777777777000000000000000000000000007777777777777777777777777777777777777777777777777777777777777777777777700000000000077777700 +77777777777000000000000000000000000077777777777777777777770000000000000007777777777777777777777777777777777770000000000077777770 +77777777770000000000000000000000000777777777777777777000000000000000000000000077777777777777777777777777777777000000000007777770 +77777777700000000000000000000000077777777777777777000000000000000000000000000000077777777777777777777777777777770000000000777777 +77777777000000000000000000000000777777777777777000000000000000000000000000000000000077777777777777777777777777777000000000077777 +77777777000000000000000000000007777777777777700000000000000000000000000000000000000000777777777777777777777777777700000000077777 +77777770000000000000000000000077777777777770000000000000000000000000000000000000000000007777777777777777777777777770000000007777 +77777700000000000000000000000777777777777000000000000000000000000000000000000000000000000077777777777777777777777777000000000777 +77777700000000000000000000007777777777700000000000000000000000000000000000000000000000000000777777777777777777777777700000000777 +77777000000000000000000000077777777777000000000000777777777777700000000000000000000000000000077777777777777777777777770000000077 +77770000000000000000000000777777777700000000007777777777777777777770000000000000000000000000000777777777777777777777777000000007 +77770000000000000000000000777777777000000007777777777777777777777777770000000000000000000000000077777777777777777777777000000007 +77700000000000000000000007777777770000007777777777777777777777777777777770000000000000000000000007777777777777777777777700000000 +77700000000000000000000077777777000000777777777777777777777777777777777777700000000000000000000000077777777777777777777770000000 +77000000000000000000000777777770000077777777777777777777777777777777777777777000000000000000000000007777777777777777777777000000 +77000000000000000000000777777700000777777777777777777700000000000777777777777700000000000000000000000777777777777777777777000000 +70000000000000000000007777777000077777777777777777000000000000000000077777777777000000000000000000000077777777777777777777700000 +70000000000000000000077777770000777777777777777700000000000000000000000777777777700000000000000000000007777777777777777777770000 +00000000000000000000077777700007777777777777700000000000000000000000000000777777770000000000000000000000777777777777777777770000 +00000000000000000000777777700777777777777777000000000000000000000000000000077777777700000000000000000000777777777777777777777000 +00000000000000000007777777007777777777777700000000000000000000000077777777700777777770000000000000000000077777777777777777777700 +00000000000000000007777770077777777777777000000000000000000000077777777777777777777777000000000000000000007777777777777777777700 +00000000000000000077777700777777777777770000000000000000000007777777777777777777777777700000000000000000000777777777777777777770 +00000000000000000077777700777777777777700000000000000000000777777777777777777777777777700000000000000000000777777777777777777770 +00000000000000000777777007777777777777000000000000000000007777777777777777777777777777770000000000000000000077777777777777777777 +00000000000000000777770077777777777770000000000000000000077777777777777777777777777777777000000000000000000007777777777777777777 +00000000000000000777770777777777777700000000000000000000777777777770000000777777777777777700000000000000000007777777777777777777 +00000000000000007777700777777777777000000000000000000007777777777000000000007777777777777700000000000000000000777777777777777777 +00000000000000007777707777777777770000000000000000000077777777770000000000000777777777777770000000000000000000777777777777777777 +00000000000000077777077777777777770000000000000000000777777777700000000000000077777777777777000000000000000000077777777777777777 +00000000000000077777077777777777700000000000000000000777777777000000000000000007777777777777000000000000000000077777777777777777 +00000000000000077770777777777777000000000000000000007777777770000000000000000000777777777777700000000000000000007777777777777777 +00000000000000777770777777777777000000000000000000007777777770000000000000000000777777777777700000000000000000007777777777777777 +00000000000000777707777777777777000000000000000000077777777700000000000000000000077777777777770000000000000000000777777777777777 +00000000000000777707777777777770000000000000000000077777777700000000000000000000077777777777770000000000000000000777777777777777 +00000000000000777707777777777770000000000000000000077777777770000000000000000000077777777777770000000000000000000777777777777777 +00000000000007777077777777777700000000000000000000777777777700000000000000000000077777777777777000000000000000000077777777777777 +00000000000007777077777777777700000000000000000000777777777700000000000000000000077777777777777000000000000000000077777777777777 +00000000000007777077777777777700000000000000000000777777777700000000000000000000077777777777777000000000000000000077777777777777 +00000000000007770777777777777700000000000000000000777777777700000000000000000000077777777777777700000000000000000007777777777777 +00000000000007770777777777777000000000000000000000777777777770000000000000000000777777777777777700000000000000000007777777777777 +00000000000007770777777777777000000000000000000000777777777770000000000000000000777777777777777700000000000000000007777777777777 +00000000000077770777777777777000000000000000000000777777777777000000000000000007777777777777777700000000000000000007777777777777 +00000000000077777777777777777000000000000000000000777777777777700000000000000077777777777777777770000000000000000007777777777777 +00000000000077707777777777777000000000000000000000777777777777770000000000000777777777777777777770000000000000000000777777777777 +00000000000077707777777777777000000000000000000000077777777777777000000000007777777777777777777770000000000000000000777777777777 +00000000000077707777777777777000000000000000000000077777777777777770000000777777777777777777777770000000000000000000777777777777 +00000000000077707777777777777000000000000000000000077777777777777777777777777777777777777777777770000000000000000000777777777777 +00000000000077707777777777777000000000000000000000007777777777777777777777777777777777777077777770000000000000000000777777777777 +00000000000077707777777777777000000000000000000000007777777777777777777777777777777777777077777770000000000000000000777777777777 +00000000000077707777777777777000000000000000000000000777777777777777777777777777777777770077777770000000000000000000777777777777 +00000000000077707777777777777700000000000000000000000777777777777777777777777777777777770777777770000000000000000000777777777777 +00000000000077707777777777777700000000000000000000000077777777777777777777777777777777700777777770000000000000000000777777777777 +00000000000077707777777777777700000000000000000000000007777777777777777777777777777777000777777770000000000000000000777777777777 +00000000000077707777777777777700000000000000000000000000777777777777777777777777777770000777777770000000000000000000777777777777 +00000000000077707777777777777770000000000000000000000000077777777777777777777777777700007777777770000000000000000000777777777777 +00000000000077700777777777777770000000000000000000000000007777777777777777777777777000007777777700000000000000000000777777777777 +00000000000007700777777777777777000000000000000000000000000777777777777777777777770000077777777700000000000000000000777777777777 +00000000000007700777777777777777000000000000000000000000000007777777777777777777000000077777777700000000000000000000777777777777 +00000000000007770777777777777777000000000000000000000000000000077777777777777700000000077777777700000000000000000007777777777777 +00000000000007770077777777777777700000000000000000000000000000000077777777700000000000777777777000000000000000000007777777777777 +00000000000007770077777777777777770000000000000000000000000000000000000000000000000007777777777000000000000000000007777777777777 +00000000000007770077777777777777770000000000000000000000000000000000000000000000000007777777777000000000000000000007777777777777 +00000000000000770007777777777777777000000000000000000000000000000000000000000000000077777777770000000000000000000007777777777777 +00000000000000777007777777777777777700000000000000000000000000000000000000000000000777777777770000000000000000000077777777777777 +00000000000000777007777777777777777770000000000000000000000000000000000000000000007777777777770000000000000000000077777777777777 +00000000000000777000777777777777777777000000000000000000000000000000000000000000077777777777700000000000000000000077777777777777 +00000000000000077700777777777777777777700000000000000000000000000000000000000000777777777777700000000000000000000777777777777777 +00000000000000077700077777777777777777770000000000000000000000000000000000000007777777777777000000000000000000000777777777777777 +00000000000000077700077777777777777777777000000000000000000000000000000000000077777777777777000000000000000000000777777777777777 +00000000000000007770007777777777777777777700000000000000000000000000000000000777777777777770000000000000000000007777777777777777 +00000000000000007770000777777777777777777777000000000000000000000000000000077777777777777700000000000000000000007777777777777777 +00000000000000000777000777777777777777777777700000000000000000000000000000777777777777777700000000000000000000077777777777777777 +70000000000000000777000077777777777777777777777700000000000000000000000777777777777777777000000000000000000000077777777777777777 +70000000000000000777700007777777777777777777777777000000000000000000077777777777777777770000000000000000000000777777777777777777 +77000000000000000077700000777777777777777777777777777700000000000777777777777777777777700000000000000000000000777777777777777770 +77000000000000000077770000777777777777777777777777777777777777777777777777777777777777700000000000000000000007777777777777777770 +77700000000000000007770000077777777777777777777777777777777777777777777777777777777777000000000000000000000007777777777777777700 +77700000000000000007777000007777777777777777777777777777777777777777777777777777777770000000000000000000000077777777777777777700 +77770000000000000000777700000777777777777777777777777777777777777777777777777777777700000000000000000000000777777777777777777000 +77770000000000000000077700000007777777777777777777777777777777777777777777777777770000000000000000000000000777777777777777770000 +77777000000000000000077770000000777777777777777777777777777777777777777777777777700000000000000000000000007777777777777777770000 +77777700000000000000007777000000077777777777777777777777777777777777777777777777000000000000000000000000077777777777777777700000 +77777700000000000000000777700000000777777777777777777777777777777777777777777700000000000000000000000000777777777777777777000000 +77777770000000000000000777700000000077777777777777777777777777777777777777777000000000000000000000000000777777777777777777000000 +77777777000000000000000077770000000000777777777777777777777777777777777777700000000000000000000000000007777777777777777770000000 +77777777000000000000000007777000000000007777777777777777777777777777777770000000000000000000000000000077777777777777777700000000 +77777777700000000000000000777700000000000007777777777777777777777777770000000000000000000000000000000777777777777777777000000000 +77777777770000000000000000777770000000000000007777777777777777777770000000000000000000000000000000007777777777777777777000000000 +77777777777000000000000000077777000000000000000000777777777777700000000000000000000000000000000000077777777777777777770000000000 +77777777777000000000000000007777770000000000000000000000000000000000000000000000000000000000000007777777777777777777700000000000 +77777777777700000000000000000777777000000000000000000000000000000000000000000000000000000000000077777777777777777777000000000000 +77777777777770000000000000000077777700000000000000000000000000000000000000000000000000000000000777777777777777777770000000000000 +77777777777777000000000000000007777777000000000000000000000000000000000000000000000000000000077777777777777777777700000000000000 +77777777777777700000000000000000777777700000000000000000000000000000000000000000000000000000777777777777777777777000000000000000 +77777777777777770000000000000000077777777000000000000000000000000000000000000000000000000077777777777777777777770000000000000000 +77777777777777777000000000000000000777777770000000000000000000000000000000000000000000007777777777777777777777000000000000000000 +77777777777777777700000000000000000077777777700000000000000000000000000000000000000000777777777777777777777770000000000000000007 +07777777777777777770000000000000000007777777777000000000000000000000000000000000000077777777777777777777777700000000000000000077 +00777777777777777777000000000000000000077777777777000000000000000000000000000000077777777777777777777777770000000000000000000777 +00077777777777777777770000000000000000007777777777777000000000000000000000000077777777777777777777777777700007000000000000007777 +00007777777777777777777000000000000000000077777777777777770000000000000007777777777777777777777777777770000070000000000000077777 +00000777777777777777777700000000000000000007777777777777777777777777777777777777777777777777777777777700000700000000000000777777 +00000007777777777777777777000000000000000000077777777777777777777777777777777777777777777777777777770000070000000000000007777777 +70000000777777777777777777700000000000000000000777777777777777777777777777777777777777777777777777000000700000000000000077777777 +77000000077777777777777777777000000000000000000000777777777777777777777777777777777777777777777000000077000000000000000777777777 +77700000000777777777777777777700000000000000000000007777777777777777777777777777777777777777700000000700000000000000007777777777 + diff --git a/perfgraphdemo.p8 b/perfgraphdemo.p8 deleted file mode 100644 index a4d539e..0000000 --- a/perfgraphdemo.p8 +++ /dev/null @@ -1,33 +0,0 @@ -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