Search code examples
javaswingjava-2dmeasurementframe-rate

How to measure Java2D drawing performance in a JComponent?


I'm trying something along these lines:

private static class TexturePanel extends JPanel {

    @Override
    protected void paintComponent(Graphics graphics) {

        // drawing code

        // calc fps

        repaint();
    }
}

Is calling repaint() in paintComponent() the right approach to this?


Solution

  • How to measure Java2D drawing performance in a JComponent?

    A crude measure is to give the repaint Timer an arbitrarily short delay & count FPS.

    Is calling repaint() in paintComponent() the right approach to this?

    No. No it isn't. paintComponent() is fine, but don't trigger repaint() from within the method. See the Performing Custom Painting Lesson of the Java Tutorial for some tips.

    If you cannot get it sorted from that, I suggest you prepare and post an SSCCE of your best effort.