title: A timer that measures length of mouse click
body: <p>I put this together using examples I could find from vanilla js, because I couldn't find exactly what I needed that was already done in p5. </p>
  
  <p>It's doing what I want it to do which is give me a time between mousePressed and mouseReleased.</p>
  
  <p>Question: is my method efficient? Looking for some expert advice after reading other comments about timers...don't want a timer running in the background because I haven't handled it correctly...</p>
  
  <pre><code>let timeTaken = 0;
  let result = 0;
  let timer;
  
  function setup() {
    createCanvas(500,500);
  }
  
  function draw() {
    background('black');
    fill('white');
    textSize(15);  
    text("timeTaken: "+timeTaken,20,20);
    textSize(60);
    text(result,100,100);
  }
  
  function mousePressed() {
    result = 0;
    timeTaken = 0;
    if (timer) {
        clearInterval(timer);
    }
    timer = setInterval(()=&gt;{timeTaken++;}, 1);  
  }
  
  function mouseReleased() {
    clearInterval(timer);
    result = timeTaken;
  }
  </code></pre>