1
2
3 package org.freehep.graphics2d.test;
4
5 import java.awt.Color;
6 import java.awt.Dimension;
7 import java.awt.Insets;
8
9 import javax.swing.JFrame;
10
11 import org.freehep.graphics2d.BufferedPanel;
12 import org.freehep.graphics2d.VectorGraphics;
13
14
15
16
17
18 public class TestPerformance extends BufferedPanel {
19
20 private static final int n = 100;
21
22 private static final int m = 50;
23
24 private int[][] xip = new int[n][m];
25
26 private int[][] yip = new int[n][m];
27
28 private double[][] xdp = new double[n][m];
29
30 private double[][] ydp = new double[n][m];
31
32 private double[] xs = new double[n];
33
34 private double[] ys = new double[n];
35
36 public void paintComponent(VectorGraphics g) {
37
38 Dimension dim = getSize();
39 Insets insets = getInsets();
40
41 int width = dim.width;
42 int height = dim.height;
43
44 for (int i = 0; i < xip.length; i++) {
45 for (int j = 0; j < xip[0].length; j++) {
46 xip[i][j] = (int) (Math.random() * width);
47 yip[i][j] = (int) (Math.random() * height);
48 }
49 }
50
51 for (int i = 0; i < xdp.length; i++) {
52 for (int j = 0; j < xdp[0].length; j++) {
53 xdp[i][j] = Math.random() * width;
54 ydp[i][j] = Math.random() * height;
55 }
56 }
57
58 for (int i = 0; i < xs.length; i++) {
59 xs[i] = Math.random() * width;
60 ys[i] = Math.random() * height;
61 }
62
63 System.out.print("Waiting 4 seconds... ");
64 try {
65 Thread.sleep(4000);
66 } catch (InterruptedException e) {
67 }
68 System.out.println("done");
69
70
71 g.setColor(Color.black);
72 g.fillRect(insets.left, insets.top, dim.width - insets.left
73 - insets.right, dim.height - insets.top - insets.bottom);
74
75 g.setColor(Color.orange);
76 drawIntPolylines(g);
77
78 g.setColor(Color.cyan);
79 drawDoublePolylines(g);
80
81 g.setColor(Color.red);
82
83 g.setColor(Color.blue);
84
85 }
86
87 public void drawIntPolylines(VectorGraphics g) {
88 long start, end;
89
90 start = System.currentTimeMillis();
91 for (int i = 0; i < xip.length; i++) {
92 g.drawPolyline(xip[i], yip[i], xip[i].length);
93 }
94 end = System.currentTimeMillis();
95 System.out.println("VG2D:" + xip.length + " IntPolys[" + xip[0].length
96 + "] " + (end - start) + " ms");
97 }
98
99 public void drawDoublePolylines(VectorGraphics g) {
100 long start, end;
101
102 start = System.currentTimeMillis();
103 for (int i = 0; i < xdp.length; i++) {
104 g.drawPolyline(xdp[i], ydp[i], xdp[i].length);
105 }
106 end = System.currentTimeMillis();
107 System.out.println("VG2D:" + xdp.length + " DoublePolys["
108 + xdp[0].length + "] " + (end - start) + " ms");
109 }
110
111 public void drawSymbols(VectorGraphics g, int type, boolean fill) {
112
113 long start = System.currentTimeMillis();
114 for (int i = 0; i < xs.length; i++) {
115 if (fill) {
116 g.fillSymbol(xs[i], ys[i], 6, type);
117 } else {
118 g.drawSymbol(xs[i], ys[i], 6, type);
119 }
120 }
121 long end = System.currentTimeMillis();
122 System.out.println("VG2D:" + xs.length + " symbols[" + type + "] "
123 + (end - start) + " ms");
124 }
125
126 public static void main(String[] args) {
127
128
129 JFrame frame = new JFrame("Test PixelGraphics2D Performance");
130
131
132 frame.getContentPane().add(new TestPerformance());
133
134
135 frame.setSize(new Dimension(1024, 768));
136 frame.setVisible(true);
137 }
138 }