tl;dr
In the pico8 console, run load #prof
, then edit the last tab with some code you want to measure:
prof(function(x) local _=sqrt(x) -- code to measure end,function(x) local _=x^0.5 -- some other code to measure end,{ locals={9} }) -- "locals" (optional) are passed in as args |
Run the cart: it will tell you exactly how many cycles it takes to run each code snippet.
what is this?
The wiki is helpful to look up CPU costs for various bits of code, but I often prefer to directly compare two larger snippets of code against each other. (plus, the wiki can get out of date sometimes)
For the curious, here's how I'm able to calculate exact cycle counts
(essentially, I run the code many times and compare it against running nothing many times, using stat(1) and stat(2) for timing)
how do I use it?
Here's an older demo to wow you:
This is neat but impractical; for everyday usage, you'll want to load #prof
and edit the last tab.
The cart comes with detailed instructions, reproduced here for your convenience:
There are also instructions included on two alternate ways you can profile your code, without using prof
:
various results
Here are some speed comparisons I found interesting. Some of these may be out of date now, but they were interesting:
credits
Cart by pancelor.
Thanks to @samhocevar for the initial snippet that I used as a basis for this profiler!
Thanks to @freds72 and @luchak for discussing an earlier version of this with me!
Thanks to thisismypassword for updating the wiki's CPU page!
changelog
the profiler is missing an input variable somehow - the current pattern forces declaration of a local (or global) to mimic real life usage
qol request: copy results to clipboard
good points -- added! passing input variables is slightly awkward, but it's at least possible now
I've updated the description + cart (load #prof
) to be a lot clearer
[Please log in to post a comment]