# How can I fix stuttering. Is it due to unoptimized code?

**URL:** <https://discourse.processing.org/t/how-can-i-fix-stuttering-is-it-due-to-unoptimized-code/32160>\
**Category:** Coding Questions\
**Created:** [September 9, 2021, 6:31am UTC](https://discourse.processing.org/t/how-can-i-fix-stuttering-is-it-due-to-unoptimized-code/32160 "2021-09-09T06:31:46Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 9, 2021, 10:31am UTC](https://discourse.processing.org/t/how-can-i-fix-stuttering-is-it-due-to-unoptimized-code/32160/7 "2021-09-09T10:31:57Z")

</div>

Hello again…

You can add some code to monitor these stutters:

> [@FrameRate hiccups](https://discourse.processing.org/t/framerate-hiccups/11947/15):
>
> I had some fun visualizing the data available to me. I displayed frameRate data (which averages) to framerate calculated from time between frames. [https://processing.org/reference/frameRate.html](https://processing.org/reference/frameRate.html) Code (you will have to select use “true” or “false” to see different modes of output): PrintWriter output; Table table; int time = 16\*60+40; //16s\*60f/s = 960f hiccups end after this time boolean dispMode = true; // "true" stores to file and plots after "time", "false" plots in real time lo…

I got carried away with above…

It can be as simple as

- checking time between frames using `millis()`
- if it is much greater than 1/60fps = 17 ms (rounded up to nearest int) display something using println() or flash screen colors.
- println() every frame can also slows things down so only use this with an `if()`

If you just monitor `frameRate` there is some averaging:

> **[frameRate / Reference](https://processing.org/reference/frameRate.html)**
>
> The system variable frameRate contains the approximate frame rate of the software as it executes. The initial value is 10 fps and is updated with each frame. The value is averaged (integrated) …

Time between frames show the spikes.

`:)`

---

_[View the full topic](https://discourse.processing.org/t/how-can-i-fix-stuttering-is-it-due-to-unoptimized-code/32160)._
