How do I measure time using Minueto?

Minueto provides the tools needed to measure time. This can be useful to measure the frame rate or properly time your animations. The MinuetoStopWatch class functions like a stopwatch. It measures time in milliseconds and is control through the invocation of its start/stop/reset methods.

To use a stopwatch, you need to initialize a stopwatch object.

MinuetoStopWatch stopWatch = new MinuetoStopWatch();
    

You can then use the start/stop method to start/stop the stopwatch.

stopWatch.start();
stopWatch.stop();
    

At any time, you can get the value of the stopwatch (time elapse since the start method was called) by using the getTime method. Remember that the stopwatch measures time in milliseconds, thus the return value of getTime will be in milliseconds.

long timeNeeded = stopWatch.getTime();
    

You can also reset the stopwatch (stop it and return its value to 0) by calling the reset method.

Here is the full source code of a program that will measure the time needed to draw a frame from the How do I draw a line? howto.

import org.minueto.*; 
import org.minueto.handlers.*; 
import org.minueto.image.*; 
import org.minueto.window.*;  
        
public class Demo {


    public static void main(String[] args) {

        MinuetoWindow window; 
        MinuetoImage redX;
        MinuetoStopWatch stopWatch;
    
        window = new MinuetoFrame(640, 480, true);
        redX = new MinuetoImage(50,50);
        redX.drawLine(MinuetoColor.RED, 0, 0, 49, 49);
        redX.drawLine(MinuetoColor.RED, 0, 49, 49, 0); 
        stopWatch = new MinuetoStopWatch();

        window.setVisible(true);
        stopWatch.start();

        while(true) { 

            window.draw(redX, 10, 10);
            window.render();
            Thread.yield();

            stopWatch.stop();
            System.out.println("It took " + stopWatch.getTime() + " milliseconds.");
            stopWatch.reset();
            stopWatch.start();
        }
    }
}