How to analyze the computational overhead of a Processing Sketch

Please forgive me if the terms are inaccurate or this is the wrong forum.

Essentially I write sketches in Processing and I am struggling to find out why my code runs slow.

Sometimes a sketch runs fast and I have no idea why other than there are less lines of code. Sometimes a different sketch runs slow and I have no idea why.

I am curious if there is a way within the Processing IDE, or maybe a general tool, to determine or analyze which lines of code are causing the sketch to run slow?

Such as a way to isolate “Oh, these lines are causing it to run the slowest. Looks like it’s a section of this loop. Maybe I should concentrate on improving this function rather than searching for a needle in a haystack.”

Similar to how when my computer is running slow I can use task manager to take a look at which programs are running slow and then adjust. I don’t just guess. Or develop an unfounded penchant for quitting one program over another.

I of course could upload my sketch but this is a example independent problem I am trying to get better at solving. I would like to find a way to analyze all sketches. Or even code in different languages, etc.

If there is no general tool for analyzing a Processing sketch how do people go about this? Surely there must be a better method than trial and error, brute force, intuition, or otherwise. Of course those methods could yield better running code but there must be some formal analysis.

Even if you didn’t have anything specific to share for Processing any suggestions on search terms, subjects, or topics would be appreciated as I have no idea how to proceed other than the brute force/trial and error method.

Thank you,


You could use Visual VM but it takes some getting used to.


There is no correlation between the numbers of lines of code and how fast the sketch runs. It depends on what the code is doing and whether you are using the best algorithms for doing it

Thank you all for the tips I am going to do some research on VisualVM.

Does anyone have any good references on how to get started using that with Processing?

Possibly in past discussions – or those users might be able to point to resources…

Mmm you can use a timer to see how many times does your functions takes, I use it in AS (Android Studio), but I’m pretty sure you can use it in java mode in the Processing IDE.

Recently I got a new tablet and my code that was running at 20-19 fps, now runs at 60 fps, so the total time depends on many things (hardware, software), but you can check what functions are taking more time and focus on them…

hope it helps in something, good luck :four_leaf_clover: !!