Log In  


Hey guys,

I'm new to Pico-8, and I love the general concept of this! I'm already in the middle of some cool development.. and hit all the borders: compressed code size exceeded, out of memory in the late game, and generally high cpu load in the late game.

For memory profiling, I use a function to recursively count the elements in a table. This is good enough for that task.

The question is how to do cpu profiling in pico-8? The goal is to identify the parts of the code, which use up most cpu time. Something like this would be sufficient for me:

function oh_this_might_take_long()
    local start = time()
    -- .... do some intensive stuff ....
    printh("this took "..(time()-start).." seconds")
end

However, this would not work out very well, because time() is too inaccurate. It increments in steps of 0.03335. This is the duration of one frame (1s/30f = 0.03335 s/f), so time() does not help with this.

Any ideas on how to do cpu profiling on pico-8?

thanks,
sulai



Yup, time() sucks for timing things. Use stat(1)instead. IIRC it updates a couple hundred times per frame. Just keep in mind it measures frames, not seconds.


Felice, this is awesome! This is working for me:

function oh_this_might_take_long()
    local start = stat(1)
    -- .... do some intensive stuff ....
    printh("this took "..((stat(1)-start)*100).."% of a frame")
end

I'm going to post this in "Snippeds" as well, for the help of others :)



[Please log in to post a comment]