I am trying to optimize application performance by switching from Java2D to OpenGL (LWJGL). I wrote myself some guidelines to see the difference in performance between the two and was pleased with the result at the beginning. However, when I ran my tests on another machine, the result was quite shocking to me.
This is a benchmark:
public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame();
frame.setSize(1000, 1000);
frame.setLocation(0, 0);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JComponent() {
protected void paintComponent(Graphics graphics) {
Graphics2D g = (Graphics2D) graphics;
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setFont(g.getFont().deriveFont(24f));
long start = System.nanoTime();
for(int i=0;i<500;i++){
g.drawString("This is a test string - This is a test string - This is a test string",10, 20+i*2);
}
long end = System.nanoTime();
long nsDuration = (end-start);
System.out.println("DrawString takes: "+(nsDuration/1_000_000)+" ms");
}});
frame.setVisible(true);
boolean t=true;
while(t){
frame.repaint();
Thread.sleep(1000);
}
}
I developed it on my desktop computer (CPU: i3-3220, GPU: HD7850), where I get this output:
DrawString takes: 281 ms
DrawString takes: 299 ms
DrawString takes: 282 ms
The OpenGL version of the test gave me about ~ 4 ms, so ~ 75 times better, which seems good.
10-, (CPU: P8600, GPU: Intel GMA 4500MHD), OpenGL, Java2D ~ 20 . , :
. JRE (1.8.1xx), (Windows 8.1). , Java , JVM "-Dsun.java2d.opengl = false" - .
, , , , - , iGPU - , . iGPU (HD Graphics 2500), . , ~ 7 iGPU.
, , ...
- - , Java2D iGPU?
- UI ( ) 290 ?
- () Java2D?
EDIT: , , , iGPU - , AMD/ATI... , - NVIDIA, :)