FrameRate hiccups

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

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

long lastTime;
long currTime;
long diffTime;

void setup() 
  {
  size(1000, 600, P3D);
  background(0);
  frameRate(60);
  
  if (!dispMode)
    {
    output = createWriter("frameRate.csv");
    output.println("frameCount" + "," + "frameRate");
    textSize(30);
    textAlign(CENTER, CENTER);
  //  text("Please wait for "+ time + " frameCounts...", width/2, height/2);
    text("Please wait for "+ time/60 + " seconds...", width/2, height/4);
    lastTime = System.nanoTime(); 
    }
  }

void draw() 
  {
  if (dispMode)
    {
    currTime = System.nanoTime();
    diffTime = currTime - lastTime;
  //  println(frameCount, frameRate, 1000000000.0/diffTime);
    lastTime = currTime;
   
    if (frameCount%width == 0)
      background(0);   
    float scale = 5;
    float size = map(abs(1000000000.0/diffTime-60), 0, 100, 2, 30);
    strokeWeight(size);
    stroke(0, 255, 0);
    point(frameCount%width, float(height) - scale*1000000000.0/diffTime);
    strokeWeight(3);
    stroke(255, 255, 0);
    point(frameCount%width, float(height) - scale*(frameRate));
    }
  
  if (!dispMode)
    {
    output.println(frameCount + "," + frameRate);
    if (frameCount == time) closeFile(); 
    if (frameCount > time)
      {  
      table = loadTable("frameRate.csv", "header");  
      for (TableRow row : table.rows()) 
        {
        int x = row.getInt("frameCount");
        float y = row.getFloat("frameRate");
  
  // Add some colour
        if (y < 55)             // Red for framerate < 55
          stroke(255, 0, 0);
        else if (y < 59)        // Yellow for 55<= framerate <59 
          stroke(255, 255, 0);
        else
          stroke(0, 255, 0);    // Green for   59<= framerate  It can be > 60 fps!
  // Plot         
        strokeWeight(2);
        point(x%width, float(height)-5*y);
        }      
      }
    }
  }    

void closeFile()
  {
  output.flush();       // Writes the remaining data to the file
  output.close();       // Finishes the file
//  exit();
  }

Plot of Average Processing “frameRate” (yellow) and Calculated Framerate (green) with enhancements:

Same program where it only collects data and plots after 16s:

Data visualization can be fun!