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

P#43655 2017-08-26 16:37 ( Edited 2017-08-27 12:38)

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.

P#43657 2017-08-26 16:47 ( Edited 2017-08-26 20:47)

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 :)

P#43675 2017-08-27 08:38 ( Edited 2017-08-27 12:38)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 12:01:32 | 0.005s | Q:10